#P3377. 【模板】可并堆 1
【模板】可并堆 1
Description
As stated, initially there are min-heaps, each containing exactly one number. Afterwards, you need to support two types of operations:
-
1 x y: Merge the min-heap containing the -th number and the min-heap containing the -th number (if the -th or -th number has already been deleted, or if the -th and -th numbers are in the same heap, ignore this operation). -
2 x: Output the minimum number in the heap containing the -th number, and delete this minimum number (if there are multiple minimum numbers, delete the one that was inserted earlier; if the -th number has already been deleted, output and ignore the deletion).
Input Format
The first line contains two positive integers , representing the initial number of min-heaps and the number of subsequent operations, respectively.
The second line contains positive integers, where the -th integer is the only number initially contained in the -th min-heap.
Each of the next lines contains or positive integers, representing one operation in the following formats:
Operation 1: 1 x y
Operation 2: 2 x
Output Format
The output contains several lines of integers, each corresponding to the result of an operation of type 2, in order.
5 5
1 5 4 2 3
1 1 5
1 2 5
2 2
1 4 2
2 2
1
2
Hint
【Constraints】
For of the testdata: , .
For of the testdata: , .
For of the testdata: , , and all initial numbers in the min-heaps are within the int range.
【Sample Explanation】
Initially, the five min-heaps are: , , , , .
In the first operation, merge the heap containing the -st number with the heap containing the -th number, resulting in four min-heaps: , , , .
In the second operation, merge the heap containing the -nd number with the heap containing the -th number, resulting in three min-heaps: , , .
In the third operation, output and delete the minimum of the heap containing the -nd number, so output ; the first number is deleted, and the three min-heaps become: , , .
In the fourth operation, merge the heap containing the -th number with the heap containing the -nd number, resulting in two min-heaps: , .
In the fifth operation, output and delete the minimum of the heap containing the -nd number, so output ; the fourth number is deleted, and the two min-heaps become: , .
Therefore, the outputs are and in order.
Translated by ChatGPT 5
京公网安备 11011102002149号