#P10214. [CTS2024] 投票游戏
[CTS2024] 投票游戏
Problem Description
There are people, numbered from to . Person has a hated person . Person has no hated person.
On this day, the people play a voting game. One game consists of rounds. At the start of the game, no one has been voted out. In each round of the game, the following process is performed:
- For each person who has not been voted out, they initially have votes.
- Then, for each person who has not been voted out, if they have a hated person and their hated person has not been voted out, then they cast votes for .
- Finally, vote out the person (among those not yet voted out) with the highest number of votes. If there are multiple people with the highest number of votes, vote out the one with the largest index.
The votes in the rounds of one game are counted independently.
Before the game starts, events happen. There are two types of events:
- Given , modify to .
- Xiaoming wants to know: given two people , if a game is played at this moment, which one of the two will be voted out first.
As Xiaoming’s friend, can you help him?
Input Format
Read input from standard input.
The first line contains two positive integers , representing the number of people and the number of events.
The second line contains integers .
The third line contains integers .
The fourth line contains integers .
The next lines each contain three or four integers describing an event. The first positive integer indicates the type of the event.
- If , then the next three integers are , meaning modifying to .
- If , then the next two positive integers are . You need to determine, if a game is played now, which of and will be voted out first.
Output Format
Write output to standard output.
For each event with , output one line containing one character in 01. If is voted out first, output 0, otherwise output 1.
5 8
1 2 3 2
1 3 2 1 0
0 4 1 0 0
2 1 3
1 1 0 3
2 2 5
1 1 2 2
2 4 3
2 5 4
2 5 1
2 2 1
0
0
1
1
1
1
Hint
For all testdata:
- .
- .
- .
- .
- .
| Subtask ID | Points | Special Property | ||
|---|---|---|---|---|
| 1 | 5 | None | ||
| 2 | 10 | |||
| 3 | is uniformly random in | |||
| 4 | 15 | |||
| 5 | 30 | |||
| 6 | None | |||
Translated by ChatGPT 5