#K87972. Mage Tournament Simulation
Mage Tournament Simulation
Mage Tournament Simulation
In this problem, you are given ( n ) mages with their respective power levels ( a_1, a_2, \dots, a_n ). The tournament consists of ( q ) queries. There are two types of queries:
- INSERT p: A new mage with power ( p ) is added to the end of the list.
- DUEL i j: A duel occurs between the mage at position ( i ) and the mage at position ( j ) (1-indexed). The mage with the higher power level wins. In the case of a tie, the mage with the lower index wins.
For every "DUEL" query, output the index (1-indexed) of the winning mage.
inputFormat
The input is given from standard input in the following format:
- The first line contains two integers ( n ) and ( q ) representing the number of initial mages and the number of queries, respectively.
- The second line contains ( n ) space-separated integers where the ( i)-th integer represents the initial power level ( a_i ) of the ( i)-th mage.
- The following ( q ) lines each contain a query in one of the two formats: "INSERT p" or "DUEL i j".
outputFormat
For each "DUEL" query, print the 1-indexed position of the winning mage on a new line to standard output.## sample
5 6
10 20 30 40 50
DUEL 1 2
DUEL 2 3
DUEL 4 5
INSERT 25
DUEL 6 3
DUEL 5 6
2
3
5
6
5
</p>