luogu#P7981. [JRKSJ R3] system

[JRKSJ R3] system

Problem Description

Define one operation on a sequence aa as setting biaaib_i \gets a_{a_i}, and then setting aibia_i \gets b_i, where i[1,n]i \in [1,n].

You are given a sequence aa of length nn. Ask for the sequence after performing the operation on aa exactly kk times.

Input Format

The first line contains two integers n,kn, k.

The second line contains nn integers representing the sequence aa.

Output Format

Output one line with nn integers, representing the sequence aa after kk operations.

5 2
2 5 4 3 1
2 5 3 4 1
20 233
1 1 5 6 8 15 10 11 18 14 4 16 16 11 3 5 1 15 4 5
1 1 4 5 6 8 4 15 5 6 3 11 11 15 11 4 1 8 3 4

Hint

Sample Explanation

For Sample 11, the changes of aa are as follows:

5,1,3,4,25,1,3,4,2 2,5,3,4,12,5,3,4,1

Constraints

This problem uses bundled testdata.

Subtask\text{Subtask} nn \le Special Property Score
11 10410^4 A\text A 55
22 10210^2 None 1515
33 10410^4 B\text B 1010
44 5×1055\times 10^5 2020
55 C\text C
66 None 3030

Property A\text A: 0k1030 \le k \le 10^3.
Property B\text B: ai=imodn+1a_i = i \bmod n + 1.
Property C\text C: aa is a permutation of [1,n][1,n].

For 100%100\% of the testdata, 1n5×1051 \le n \le 5 \times 10^5, 0k1090 \le k \le 10^9, 1ain1 \le a_i \le n.

Translated by ChatGPT 5