#abc377e. E - Permute K times 2

E - Permute K times 2

Score : 475475 points

问题陈述

给定一个排列 P=(P1,P2,,PN)P=(P_1,P_2,\ldots,P_N),它是 (1,2,,N)(1,2,\ldots,N) 的一个排列。

将执行 KK 次以下操作:

  • 对于 i=1,2,,Ni=1,2,\ldots,N同时更新 PiP_iPPiP_{P_i}

打印所有操作完成后的 PP

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given a permutation P=(P1,P2,,PN)P=(P_1,P_2,\ldots,P_N) of (1,2,,N)(1,2,\ldots,N).

The following operation will be performed KK times:

  • For i=1,2,,Ni=1,2,\ldots,N, simultaneously update PiP_i to PPiP_{P_i}.

Print PP after all operations.

Constraints

  • 1N2×1051\leq N\leq2\times10^5
  • 1K10181\leq K\leq10^{18}
  • 1PiN (1iN)1\leq P_i\leq N\ (1\leq i\leq N)
  • PiPj (1i<jN)P_i\neq P_j\ (1\leq i\lt j\leq N)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN KK

P1P_1 P2P_2 \ldots PNP_N

Output

For the PP after all operations, print P1,P2,,PNP_1,P_2,\ldots,P_N in this order, separated by spaces.

Sample Input 1

6 3
5 6 3 1 2 4

Sample Output 1

6 1 3 2 4 5

With each operation, PP changes as follows:

  • After the first operation, PP is (2,4,3,5,6,1)(2,4,3,5,6,1).
  • After the second operation, PP is (4,5,3,6,1,2)(4,5,3,6,1,2).
  • After the third operation, PP is (6,1,3,2,4,5)(6,1,3,2,4,5).

Thus, print 6 1 3 2 4 5.

Sample Input 2

5 1000000000000000000
1 2 3 4 5

Sample Output 2

1 2 3 4 5

Since Pi=iP_i=i, PP does not change no matter how many operations are performed.

Sample Input 3

29 51912426
7 24 8 23 6 1 4 19 11 18 20 9 17 28 22 27 15 2 12 26 10 13 14 25 5 29 3 21 16

Sample Output 3

18 23 16 24 21 10 2 27 19 7 12 8 13 5 15 26 17 4 3 9 1 22 25 14 28 11 29 6 20