Logo
(追記) (追記ここまで)

26408번 - Game 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 1024 MB144436.364%

문제

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:

  1. Player 0 either skips his turn or makes $x$ equal to $(x + a_0) \bmod n$.
  2. Player 1 either skips his turn or makes $x$ equal to $(x + a_1) \bmod n$.
  3. $\ldots$
  4. Player $n - 1$ either skips his turn or makes $x$ equal to $(x + a_{n-1}) \bmod n$.

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.

제한

예제 입력 1

2
0 0
1
1 1

예제 출력 1

0
1

예제 입력 2

3
2 1 2
3
2 1
1 2
2 2

예제 출력 2

1
0
0
2

예제 입력 3

4
0 1 1 3
2
3 2
2 2

예제 출력 3

3
0
2

힌트

출처

Camp > Moscow Pre-Finals ACM ICPC Workshop > Moscow Pre-Finals ACM ICPC Workshop 2018 G번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /