#P11266. 【模板】可并堆 2
【模板】可并堆 2
Background
Thanks to
gen。
Problem Description
Given positive integers and , and an integer sequence of length .
You need to maintain the sequence and sets . Initially, .
Then you will perform the following four types of operations for a total of times. Each operation is in one of these forms:
0 x y: Delete element from set . It is guaranteed that is in at this moment.1 x: Query . It is guaranteed that is non-empty at this moment.2 x y: Merge set into and clear . It is guaranteed that both and are non-empty at this moment, and after this operation there will be no further operations involving set .3 x y z: Assign to be . It is guaranteed that is in at this moment, and .
It is not hard to see that this is a heap template problem, so please finish it now.
Input Format
The first line contains two positive integers and .
The second line contains positive integers; the -th positive integer is .
The next lines each contain one operation as described above.
Output Format
For each operation 1, output one integer per line (note that it is not guaranteed to remain positive) as the answer.
5 5
1 2 3 4 4
2 4 5
3 4 5 3
1 4
0 4 5
1 4
3
4
Hint
For of the data, .
For of the data, .
For of the data, , . It is guaranteed that at any time, the absolute value of any element in any heap does not exceed (in plain words: each operation 3 decreases a single value by at most ).
For the last two test points, the setter’s handwritten heap and the pairing heap in pbds both ran in a few hundred milliseconds. If you are getting constant-factor TLE, you can message privately.
Translated by ChatGPT 5