#P2713. 罗马游戏
罗马游戏
Description
The Roman emperor enjoys a killing game. His army has soldiers, and each soldier initially forms an independent group. A recent plane geometry test was held, and each soldier received a score. The emperor loves plane geometry and despises soldiers with low scores.
He decides to play the following game. He can issue two types of commands:
M i jMerge the groups containing and into one group. If either or is already dead, ignore this command.K iKill the lowest-scoring soldier in the group containing . If soldier is already dead, ignore this command.
After each K i command, the general should report the score of the soldier who was killed (if the command is ignored, report ).
It is guaranteed that all soldiers’ scores are pairwise distinct.
Input Format
The first line contains an integer , the number of soldiers.
The second line contains integers , where is the score of the soldier with index .
The third line contains an integer .
The -th line describes the -th command, which is either M i j or K i.
Output Format
For each K i command, output the score of the killed soldier (if such a person does not exist, output ).
5
100 90 66 99 10
7
M 1 5
K 1
K 1
M 2 3
M 3 4
K 5
K 4
10
100
0
66
Hint
Constraints:
- For of the testdata, , , . Note: In the testdata, in the command
M i j, and may already be in the same group.
Translated by ChatGPT 5
京公网安备 11011102002149号