#P15776. [JAG 2025 Summer Camp #2] All Copy Paste

[JAG 2025 Summer Camp #2] All Copy Paste

题目描述

You have a sequence A=(A1,A2,,AN)A = (A_1, A_2, \ldots, A_N) of length NN, where initially Ai=iA_i = i for all ii (1iN1 \leq i \leq N). There are QQ queries. In the qq-th query, an integer xqx_q (1xqA1 \leq x_q \leq |A|) is given and you replace AA with

$$(A_1, A_2, \ldots, A_{x_q}, A_1, A_2, \ldots, A_{|A|}, A_{x_q + 1}, A_{x_q + 2}, \ldots, A_{|A|}), $$

where A|A| denotes the current length of AA. In other words, you insert a copy of the entire sequence AA right after its first xqx_q elements.

After processing all QQ queries in order, output the first MM elements of the resulting sequence AA.

输入格式

The input is given in the following format.

$$\begin{aligned} & N \ M \ Q \\ & x_1 \\ & x_2 \\ & \vdots \\ & x_Q \end{aligned} $$

The first line contains three integers NN, MM, and QQ (1N1061 \leq N \leq 10^6, 1Mmin(106,N×2Q)1 \leq M \leq \min(10^6, N \times 2^Q), 1Q1061 \leq Q \leq 10^6). Each of the following QQ lines contains one integer xqx_q (1xqmin(1012,N×2q1)1 \leq x_q \leq \min(10^{12}, N \times 2^{q-1})), representing the parameter of the qq-th query.

输出格式

Print MM integers A1,A2,,AMA_1, A_2, \ldots, A_M, the first MM elements of the final sequence after all queries are applied, in a single line separated by spaces.

5 9 2
2
6
1 2 1 2 3 4 1 2 1
200000 10 10
234
54
2346
374
6
24
547
65
20000000
74
1 2 3 4 5 6 1 2 3 4