#P3765. 总统选举
总统选举
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
京公网安备 11011102002149号