题目描述
Problem Description
$n$ children are standing in a line, following the physical education teacher's instructions to line up and play games.
The physical education teacher will issue $T$ instructions sequentially, each containing a positive integer $k$ less than or equal to $n$.
For each instruction, the children will line up according to the following steps:
- Before the instruction is issued, the children standing in positions $1, k + 1, 2k + 1, \cdots$ from left to right should stand in positions $1, 2, \cdots$ from left to right after the instruction.
- (If $k \geq 2$) Before the instruction is issued, the children standing in positions $2, k + 2, 2k + 2, \cdots$ from left to right should stand in positions $1, 2, \cdots$ to the right of the children from the first step (originally in positions $1, k + 1, 2k + 1, \cdots$).
- (If $k \geq 3$) The children in positions $3, k + 3, 2k + 3, \cdots$ should stand to the right of the children from the second step, and so on, until all children have been arranged (regardless of whether their positions have changed).
We are given the student IDs $a_1, a_2, \cdots, a_n$ of the children from left to right initially. We want to know the student IDs of the children from left to right after $T$ instructions.
Input Format
The input consists of three lines.
The first line contains two integers $n, T$, representing the number of children and the number of instructions.
The second line contains $n$ integers $a_1, a_2, \cdots, a_n$, representing the initial student IDs of the children from left to right.
The third line contains $T$ integers, representing the $T$ instructions from the physical education teacher.
Output Format
The output consists of one line with $n$ integers, representing the student IDs of the children from left to right after $T$ instructions.
Sample Input and Output
Sample Input #1
8 4
72818 21895123 25718513 289523 52783 18520 295123 285952
1 2 3 5
Sample Output #1
72818 285952 295123 52783 18520 289523 25718513 21895123
Sample Input #2
4 1
28910 65363 274993 653516
2
Sample Output #2
28910 274993 65363 653516
Notes
Sample 1 Explanation
For convenience, we number the children sequentially from $1$ to $8$ according to their initial standing order. The table below shows the child's number in each position in the queue initially and after each instruction.
| Queue Position | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Initial | $1$ | $2$ | $3$ | $4$ | $5$ | $6$ | $7$ | $8$ |
| After First Instruction | $1$ | $2$ | $3$ | $4$ | $5$ | $6$ | $7$ | $8$ |
| After Second Instruction | $1$ | $3$ | $5$ | $7$ | $2$ | $4$ | $6$ | $8$ |
| After Third Instruction | $1$ | $7$ | $6$ | $3$ | $2$ | $8$ | $5$ | $4$ |
| After Fourth Instruction | $1$ | $8$ | $7$ | $5$ | $6$ | $4$ | $3$ | $2$ |
Sample 2 Explanation
The first three student IDs are the Luogu UIDs of the three problem setters.
Some say the student IDs are randomly generated, but they are not.
Data Size and Constraints
For $100\%$ of the data, it is guaranteed that $1 \leq n \leq 10^4$, $1 \leq T \leq 10^4$, $1 \leq k \leq n$, and $1 \leq a_i \leq 10^9$.
| Test Case Number | $n$ | $T$ | Special Constraints |
|---|---|---|---|
| 1 | $= 1$ | $\leq 5 \times 10^3$ | None |
| 2 to 4 | $\leq 10$ | $\leq 10$ | None |
| 5 | $\leq 5 \times 10^3$ | $\leq 5 \times 10^3$ | $k = 1$ |
| 6 to 8 | $\leq 5 \times 10^3$ | $\leq 5 \times 10^3$ | None |
| 9 to 10 | $\leq 10^4$ | $\leq 10^4$ | None |
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分