Choreography

시간 제한0.5초메모리 제한1024 MB

요약
시작 배열과 이동 동작이 순차적으로 추가될 때, 특정 시점까지 추가된 모든 이동을 수행한 뒤 주어진 무용수가 최종적으로 서 있는 위치를 답한다.
난이도

어려움10점 중 8점

유형
구현, 시뮬레이션, 수학
정답자
아직 제출이 없습니다

문제

The Hungarian National Dance Ensemble is practicing a new choreography. There are NN dancers in the ensemble, numbered from 00 to N−1N - 1, where NN is an even number.

At the practice sessions, the choreographer first lines up the dancers. The positions in the line are numbered from 00 to N−1N - 1, and position ii is occupied by dancer P\[i]P\[i] at the start.

After the dancers line up, the choreographer asks them to perform a sequence of moves. Each move must be completed before they begin performing the next one. The dancers are practicing 44 types of moves:

  1. Every dancer moves KK positions to the right cyclically, where 0≤K<N0 ≤ K < N. That is,

    • for each ii from 00 to N−K−1N - K - 1, inclusive, the dancer currently standing at position ii moves to position i+Ki + K, and
    • for each ii from N−KN - K to N−1N - 1, inclusive, the dancer currently standing at position ii moves to position i+K−Ni + K - N.
  2. Every dancer moves KK positions to the left cyclically, where 0≤K<N0 ≤ K < N. That is,

    • for each ii from KK to N−1N - 1, inclusive, the dancer currently standing at position ii moves to position i−Ki - K, and
    • for each ii from 00 to K−1K - 1, inclusive, the dancer currently standing at position ii moves to position i−K+Ni - K + N.
  3. For each ii from 00 to N2−1\frac{N}{2} - 1, inclusive, dancers at positions 2i2i and 2i+12i + 1 swap places.

  4. Suppose that position ii (0≤i<N0 ≤ i < N) is occupied by dancer r_ir\_i before performing this move. For each jj from 00 to N−1N - 1, inclusive, dancer jj moves to position r_jr\_j.

Note that the positions of the dancers are distinct at the end of each move.

Before the next session, the choreographer plans a sequence of MM moves for the ensemble to practice. He adds the moves to the sequence one by one. Sometimes, before adding the next move, he wonders which positions certain dancers will occupy right after performing every move that has been added to the sequence.

Your task is to simulate the dance moves planned by the choreographer and answer his questions about the positions of the dancers.

제한

  • 1≤N≤100,0001 ≤ N ≤ 100\\,000
  • 0≤P\[i]<N0 ≤ P\[i] < N (for each ii such that 0≤i<N0 ≤ i < N)
  • P\[i]≠P\[j]P\[i] \ne P\[j] (for each ii and jj such that 0≤i<j<N0 ≤ i < j < N)
  • 0≤M≤100,0000 ≤ M ≤ 100\\,000
  • 1≤Q≤200,0001 ≤ Q ≤ 200\\,000
  • 0≤K<N0 ≤ K < N
  • 0≤D<N0 ≤ D < N

예제

이 문제는 공개된 예제가 없습니다.