luogu#P4971. 断罪者

断罪者

Background

Hell on the Double Ninth Festival……

Shikieiki Yamaxanadu (hereinafter referred to as Lady Shiki) is the Chief Judge of Hell. She is usually responsible for judging the dead, deciding whether they go to Hell, Heaven, or somewhere else.

Of course, Lady Shiki can easily judge the dead, but there are too many dead people. She needs your help to judge them, so that she can spare time to preach to others.

Problem Description

A person’s sin value EE is determined by what they did while alive and their cause of death. Every bad deed has a sin value. Bad deeds may be merged into the same set. The sin value of a set is the maximum sin value among the bad deeds in that set. The things a person did in their life affect each other. We classify what they did while alive into 4 types, and the final sin value EE is determined by the sum of the sin values of all sets.

  1. Do a bad deed: has a sin value, and forms its own set.
  2. Do a good deed: sets the sin value of one bad deed to zero.
  3. Repent: for a specified set, decrease the bad deed with the maximum sin value by some amount.
  4. Know yourself: merge two sets of bad deeds.

The cause of death can be natural death, accidental death, or suicide.

  1. Natural death: no effect.
  2. Accidental death: the set with the maximum sin value can be forgiven (removed).
  3. Suicide: the maximum set’s sin value is doubled.

Input Format

The first line contains three integers T,W,KT, W, K, where there are TT people to be judged, WW is the cause of death (corresponding to the numbering in the description), and KK is defined in the output format.

The next TT groups of data describe each person. In each group, the first line contains two integers n,mn, m, representing the number of bad deeds and the number of other actions.

The second line contains nn integers, representing the sin value of each bad deed.

Lines 33 to m+2m + 2 each contain one of the following three types of inputs. (Please refer to the description to understand them.)

  • 2 A\verb!2 A!: do a good deed, setting the sin value of bad deed AA to zero.
  • 3 A B\verb!3 A B!: repent. The specified set is the set containing AA. Decrease the bad deed with the maximum sin value in that set by BB. If the maximum sin value is smaller than BB, then set that bad deed’s sin value to zero. If multiple bad deeds have the same sin value, the one with the smaller index is considered worse.
  • 4 A B\verb!4 A B!: know yourself, merging the set containing BB into the set containing AA.

Output Format

For each person, output one string and one integer on one line.

If their sin value is 00, output Gensokyo. If their sin value is greater than KK, output Hell. Otherwise, output Heaven. Then output their sin value.

1 1 10
5 2
1 2 3 4 5
2 3
4 2 4
Heaven 10
2 2 8
5 4
4 8 7 5 6
4 2 4
2 2
4 2 3
3 3 2
3 2
5 1 2
2 2
3 3 2
Hell 9
Gensokyo 0
2 1 15
5 4
1 2 3 4 5
4 2 3
3 2 100
4 1 4
4 4 1
5 4
1 2 3 4 5
3 2 15
4 2 3
4 1 4
4 3 4
Heaven 11
Heaven 9

Hint

Sample 1 Explanation

At the beginning there are five bad deeds, with sin values 1.2.3.4.51.2.3.4.5. After doing a good deed, the sin values become 1.2.0.4.51.2.0.4.5. After knowing oneself, only four sets remain, with sin values 1.4.0.51.4.0.5. Since it is natural death, the final sin value is E=1+4+5=10K&&E!=0E=1+4+5=10 \le K \&\& E!=0, so output HeavenHeaven.

Sample 2 Explanation

For the first test case of Sample 2, it is shown in the figure below. Black ovals represent sets, red numbers are sin values, and the numbers below are node indices. Since it is accidental death, the maximum set with index 55 can be forgiven, so the sin value is E=4+5E=4+5.

Notes

All data fit in 64-bit signed integers. For all testdata, mnm\le n, 1K1\le K, and the input contains no negative numbers.
Since the input may be very large, faster input methods are recommended.

Convention ①: For the operation of merging two sets, at least one set contains only one bad deed.
Convention ②: These people will not do good deeds.

Test Point ID T n Time Limit Conventions
1 10\le10 100\le100 1s1s ①②
2 300\le300
3 500\le500
4 20\le20 1000\le1000 ①②
5 3000\le3000
6 7000\le7000
7 30\le30 10000\le10000 ①②
8 30000\le30000
9 50000\le50000
10 70000\le70000 ①②
11 10\le10 100000\le100000
12 150000\le150000
13 200000\le200000 ①②
14 500000\le500000
15 1000000\le1000000 2s2s
16 ①②
17
18 2000000\le2000000
19
20
21 11 Path Compression

Translated by ChatGPT 5