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

Description

You have a sequence $A = (A_1, A_2, \ldots, A_N)$ of length $N$, where initially $A_i = i$ for all $i$ ($1 \leq i \leq N$). There are $Q$ queries. In the $q$-th query, an integer $x_q$ ($1 \leq x_q \leq |A|$) is given and you replace $A$ 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|$ denotes the current length of $A$. In other words, you insert a copy of the entire sequence $A$ right after its first $x_q$ elements. After processing all $Q$ queries in order, output the first $M$ elements of the resulting sequence $A$.

Input Format

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 $N$, $M$, and $Q$ ($1 \leq N \leq 10^6$, $1 \leq M \leq \min(10^6, N \times 2^Q)$, $1 \leq Q \leq 10^6$). Each of the following $Q$ lines contains one integer $x_q$ ($1 \leq x_q \leq \min(10^{12}, N \times 2^{q-1})$), representing the parameter of the $q$-th query.

Output Format

Print $M$ integers $A_1, A_2, \ldots, A_M$, the first $M$ elements of the final sequence after all queries are applied, in a single line separated by spaces.