#USACO446. 轮换和移位

轮换和移位

To celebrate the start of spring, Farmer John's NN cows (1N2105)(1≤N≤2⋅10^5) have invented an intriguing new dance, where they stand in a circle and re-order themselves in a predictable way.

Specifically, there are NN positions around the circle, numbered sequentially from 00 to N1N−1, with position 00 following position N1N−1. A cow resides at each position. The cows are also numbered sequentially from 00 to N1N−1. Initially, cow ii starts in position ii. You are told a set of KK positions 0A1<A2....AK<N0\leq A_1<A_2....A_K<N that are "active", meaning the cows in these positions are the next to move (1≤K≤N).

In each minute of the dance, two things happen. First, the cows in the active positions rotate: the cow at position A1A_1 moves to position A2A_2, the cow at position A2A_2 moves to position A3A_3, and so on, with the cow at position AKA_K moving to position A1A_1. All of these KK moves happen simultaneously, so the after the rotation is complete, all of the active positions still contain exactly one cow. Next, the active positions themselves shift: A1A_1 becomes A1+1,A2A_1+1,A_2 becomes A2+1A_2+1, and so on (if Ai=N1A_i=N-1 for some active position, then AiA_i circles back around to 0).

Please calculate the order of the cows after TT minutes of the dance (1≤T≤10^9).

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains three integers N,KN,K, and TT.The second line contains TT integers representing the initial set of active positions A1,A2...AKA_1,A_2...A_K. Recall that A1=0A_1=0 and that these are given in increasing order.

OUTPUT FORMAT (print output to the terminal / stdout):

Output the order of the cows after TT minutes, starting with the cow in position 00, separated by spaces.

5 3 4
0 2 3
1 2 3 4 0

For the example above, here are the cow orders and AA for the first four timesteps:

Initial, T = 0: order = [0 1 2 3 4], A = [0 2 3]
T = 1: order = [3 1 0 2 4]
T = 1: A = [1 3 4]
T = 2: order = [3 4 0 1 2]
T = 2: A = [2 4 0]
T = 3: order = [2 4 3 1 0]
T = 3: A = [3 0 1]
T = 4: order = [1 2 3 4 0]

SCORING:

  • Inputs 2-7: N≤1000,T≤10000
  • Inputs 8-13: No additional constraints.