luogu#P3765. 总统选举
总统选举
Background
The counterattack plan of the criminal forces was successfully crushed by Xiao C, and they had no choice but to surrender. The people of the State of Qiu were liberated, and the whole country celebrated. At this moment, the former president of Qiu, having failed to protect the nation, resigned and asked the great savior of the people, Xiao C, to designate the next president.
As a democrat, Xiao C decided to hold a nationwide election to determine the next president. To ensure the final president is recognized by the vast majority, Xiao C believes that one must receive more than half of all votes to become president. If no candidate meets this condition, Xiao C will have to serve as the interim president himself. To minimize this possibility, Xiao C decided to hold several small-scale primaries first; based on the results of these primaries, voters may change their votes.
Since Qiu has a large population, tallying votes and tracking changes became troublesome. Xiao C turned to you for help to solve this problem.
Problem Description
There are people in the State of Qiu, numbered . Initially, each person casts one vote in the range , indicating support for the person with that ID to become president.
There are primaries. In each primary, voters with indices are selected for a small-scale primary. Within that interval, the person who gets more than half of the votes in the interval wins. If no one wins, Xiao C designates a candidate with ID as the winner (the winner may be outside the interval). The result of each primary must be announced, and after each primary, people decide to switch their votes to the winner of that primary.
After all primaries end, announce the candidate who finally becomes president.
Input Format
The first line contains two integers , the population of Qiu and the number of primaries.
The second line contains integers, representing the votes cast by voters numbered .
Then follow lines. Each line first contains four integers , where means that if no one wins this primary, the person with ID is considered the winner. Then follow integers, representing the voters who decide to switch their votes.
Output Format
Output lines in total. The first lines represent the result of each primary. The last line represents the candidate who finally becomes president. If in the end no one still meets the winning condition, output .
5 4
1 2 3 4 5
1 2 1 1 3
5 5 1 2 2 4
2 4 2 0
3 4 2 1 4
1
5
5
2
-1
Hint
For the first of the testdata, .
For the first of the testdata, , .
For the first of the testdata, , .
For data points 6~7, it is guaranteed that all votes always remain in .
For of the testdata, , , , .
Translated by ChatGPT 5