# | Problem | Pass Rate (passed user / total user) |
---|---|---|
13303 | DS_2021_Quiz1_LinkedList |
|
Description
You are asked to implement a game about passing a bomb.
- N people are playing this game.
- That is, player a1, a2, …, aN.
- In the beginning when the game starts, a1 holds the bomb.
- In each round afterwards, we have input numbers i, j.
- If i=1, the bomb is passed from its current holder to the next jth person, and the bomb will explode after the passing completes.- For example, in the beginning, if j=2:
Player a1 (the current bomb holder) passes the bomb to player a3, and the bomb explodes.
- For example, in the beginning, if j=2:
Figure: bomb passing sequence
- If i = 2, a new player (with index j) joins this game, and this new player is placed at the next position of the bomb holder. Please note that the bomb does not explode in this round. The new index j would not collide with existing indices.
- That is, if ax has the bomb (i.e., ax is the bomb holder), then the passing sequence in the next round would be a1, a2, …, ax, j, ax+1, …, aN.
- If the bomb explodes at player ay’s hand, ay dies and is removed from the passing sequence. At the same time, the next player of ay gets another bomb immediately.
- For example, if the bomb explodes at the kth player (ak)’s hand, then ak dies and ak is removed from the sequence. At the same time, ak+1 obtains a bomb. The new passing sequence starting at the next round would be a1, a2, …, ak-1, ak+1, …, aN.
- If only one person remains in the sequence, the game stops.
- If i = -1 and j = -1, the game stops.
Please print the indices of the remaining players in the sequence, starting at the person who has the bomb. Note when the game stops, there may be one or more players.
Input
The first line has one number, N.
The second line has N numbers, denoting the indices of the players.
For the remaining lines, players pass the bomb or add players by the rules mentioned above.
- 2 ≤ N ≤ 10,000
- 1 ≤ Player index ≤ 1,000,000
- 1 ≤ #(remaining lines) ≤ 1,000,000
- 1 ≤ i ≤ 2
- 0 ≤ j ≤ 264-1
Output
Please print the indices of the remaining players in the sequence, starting at the person who has the bomb.