#P9185. [USACO23OPEN] Rotate and Shift B

[USACO23OPEN] Rotate and Shift B

题目描述

Note: The time limit for this problem is 4s, 2x the default.

To celebrate the start of spring, Farmer John's NN cows 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 0=A1<A2<<AK<N0=A_1<A_2<\dots<A_K<N that are "active", meaning the cows in these positions are the next to move.

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+1A_1+1, A2A_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 00).

Please calculate the order of the cows after TT minutes of the dance.

输入格式

The first line contains three integers N,KN, K and TT.

The second line contains KK integers representing the initial set of active positions A1,A2,,AKA_1,A_2, \dots, A_K. Recall that A1=0A_1 = 0 and that these are given in increasing order.

输出格式

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

题目大意

为了庆祝春天的开始,FJ 的 NN 头奶牛发明了一个有趣的新舞蹈。在这个舞蹈中,他们站成一个圆圈,并以一种给定的方式移动。

具体地,圆圈上有 NN 个位置,按顺序分别编号为 00N1N - 1,其中位置 N1N - 1 之后是位置 00。每个位置都有恰好一头奶牛。奶牛也按顺序分别编号为 00N1N - 1。初始状态中,编号为 ii 的奶牛位于编号为 ii 的位置。在圆圈上,有 KK 个活跃位置 0=A1<A2<<AK<N0 = A_1 < A_2 < \dots < A_K < N,在活跃位置上的奶牛将会移动。

在舞蹈的每一分钟里,都会发生两件事。首先,在活跃位置上的奶牛会发生轮换:在 A1A_1 位置的奶牛移到 A2A_2 位置,在 A2A_2 位置的奶牛移到 A3A_3 位置……在 AKA_K 位置的奶牛移到 A1A_1 位置。所有 KK 个移动同时发生,因此,在轮换结束后,每个活跃位置上仍有恰好一头奶牛。接下来,活跃位置会发生变换:A1A_1 变为 A1+1A_1 + 1A2A_2 变为 A2+1A_2 + 1,以此类推(若某个活跃位置满足 Ai=N1A_i = N - 1,则 AiA_i 变为 00)。

请求出舞蹈持续 TT 分钟后奶牛的顺序。

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]

1KN21051 \leq K \leq N \leq 2 \cdot 10^5, 1T1091\le T\le 10^9.

  • Inputs 2-7: N1000,T10000N \leq 1000, T \leq 10000.
  • Inputs 8-13: No additional constraints.