P7981 [JRKSJ R3] system
Description
Define one operation on a sequence $a$ as setting $b_i \gets a_{a_i}$, and then setting $a_i \gets b_i$, where $i \in [1,n]$.
You are given a sequence $a$ of length $n$. Ask for the sequence after performing the operation on $a$ exactly $k$ times.
Input Format
The first line contains two integers $n, k$.
The second line contains $n$ integers representing the sequence $a$.
Output Format
Output one line with $n$ integers, representing the sequence $a$ after $k$ operations.
Explanation/Hint
### Sample Explanation
For Sample $1$, the changes of $a$ are as follows:
$$5,1,3,4,2$$
$$2,5,3,4,1$$
### Constraints
This problem uses bundled testdata.
| $\text{Subtask}$ | $n \le$ | Special Property | Score |
| :----------: | :----------: | :----------: | :----------: |
| $1$ | $10^4$ | $\text A$ | $5$ |
| $2$ | $10^2$ | None | $15$ |
| $3$ | $10^4$ | $\text B$ | $10$ |
| $4$ | $5\times 10^5$ | $\text B$ | $20$ |
| $5$ | $5\times 10^5$ | $\text C$ | $20$ |
| $6$ | $5\times 10^5$ | None | $30$ |
Property $\text A$: $0 \le k \le 10^3$.\
Property $\text B$: $a_i = i \bmod n + 1$.\
Property $\text C$: $a$ is a permutation of $[1,n]$.
For $100\%$ of the testdata, $1 \le n \le 5 \times 10^5$, $0 \le k \le 10^9$, $1 \le a_i \le n$.
Translated by ChatGPT 5