시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 (추가 시간 없음) | 1024 MB | 9 | 3 | 3 | 50.000% |
Those guys are definitely teaming.
$n$ players numbered from 0 to $n-1$ are playing a game. There is a number $x$, which is initially equal to 0. There are $n$ numbers $a_i$ ($0 \leq i, a_i \leq n - 1$) that are subject to change between the rounds of the game. The game proceeds as follows:
After this process, the player with the number $x$ wins.
Each player makes a move (that is, changes $x$) if and only if he will win if he makes a move, but won't win if he doesn't. Players know that everyone plays according to this strategy.
You have to answer $q$ queries: if we change $a_x$ to $y$ who will win the game? Note that the changes are not reverted after each query.
The first line of input contains a single integer $n$ ($1 \leq n \leq 10^5$) --- the number of players.
The second line contains $n$ integers --- initial values of $a_i$ ($0 \leq a_i \leq n - 1$).
The third line contains a single integer $q$ ($0 \leq q \leq 10^5$) --- the number of queries.
$q$ lines follow. $i$-th of them contains two integers $x_i$ and $y_i$ ($0 \leq x_i, y_i \leq n - 1$) meaning that $a_{x_i}$ is equal to $y_i$ from this query onwards.
Output $q+1$ integers. $i$-th them should be the number of the winner of the game after $i-1$ queries.
2 0 0 1 1 1
0 1
3 2 1 2 3 2 1 1 2 2 2
1 0 0 2
4 0 1 1 3 2 3 2 2 2
3 0 2