#P9185. Circular Dance

    ID: 22340 Type: Default 1000ms 256MiB

Circular Dance

Circular Dance

To celebrate the start of spring, Farmer John's \(N\) cows have invented an intriguing new dance. The cows are arranged in a circle with positions numbered \(0\) to \(N-1\) (with position \(0\) following position \(N-1\)), and initially cow \(i\) is in position \(i\). A set of \(K\) positions \(0 = A_1 < A_2 < \cdots < A_K < N\) is declared active. In each minute of the dance the following two steps occur simultaneously:

  1. Rotation: For the active positions \(A_1, A_2, \dots, A_K\), the cow at position \(A_1\) moves to position \(A_2\), the cow at \(A_2\) moves to \(A_3\), \(\dots\), and the cow at \(A_K\) moves to \(A_1\).
  2. Shift: All active positions are incremented by \(1\) (modulo \(N\)); that is, each active position \(A_i\) becomes \((A_i+1) \bmod N\).

Please compute the order of the cows after \(T\) minutes of the dance.

Note: The time limit for this problem is 4 seconds (twice the default).

Formulas in \(\LaTeX\) format:

  • Positions: \(0,1,2,\dots, N-1\)
  • Active positions: \(0=A_1 < A_2 < \cdots < A_K < N\)
  • Rotation mapping: For every \(i\) (with indices taken modulo \(K\)), the cow at position \(A_i\) moves to position \(A_{i+1}\) (with \(A_{K+1}=A_1\)).
  • Shift: Each active position \(A_i\) becomes \((A_i+1) \bmod N\).

inputFormat

The input consists of two lines:

  • The first line contains three integers \(N\), \(K\), and \(T\) separated by spaces.
  • The second line contains \(K\) distinct integers \(A_1, A_2, \dots, A_K\) in increasing order, representing the initial active positions.

outputFormat

Output a single line containing \(N\) integers. The \(i^{th}\) integer represents the label of the cow in position \(i\) after \(T\) minutes. The numbers should be separated by a single space.

sample

5 2 1
1 3
0 3 2 1 4