#abc367e. E - Permute K times

E - Permute K times

Score : 450450 points

问题陈述

给定一个长度为 NN 的序列 XX,其中每个元素的值在 11NN 之间(包括 11NN),以及一个长度为 NN 的序列 AA
请打印对 AA 执行以下操作 KK 次的结果。

  • BB 替换 AA,使得 Bi=AXiB_i = A_{X_i}

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

Problem Statement

You are given a sequence XX of length NN where each element is between 11 and NN, inclusive, and a sequence AA of length NN.
Print the result of performing the following operation KK times on AA.

  • Replace AA with BB such that Bi=AXiB_i = A_{X_i}.

Constraints

  • All input values are integers.
  • 1N2×1051 \le N \le 2 \times 10^5
  • 0K10180 \le K \le 10^{18}
  • 1XiN1 \le X_i \le N
  • 1Ai2×1051 \le A_i \le 2 \times 10^5

Input

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

NN KK

X1X_1 X2X_2 \dots XNX_N

A1A_1 A2A_2 \dots ANA_N

Output

Let AA' be the sequence AA after the operations. Print it in the following format:

A1A'_1 A2A'_2 \dots ANA'_N

Sample Input 1

7 3
5 2 6 3 1 4 6
1 2 3 5 7 9 11

Sample Output 1

7 2 3 5 1 9 3

In this input, X=(5,2,6,3,1,4,6)X=(5,2,6,3,1,4,6) and the initial sequence is A=(1,2,3,5,7,9,11)A=(1,2,3,5,7,9,11).

  • After one operation, the sequence is (7,2,9,3,1,5,9)(7,2,9,3,1,5,9).
  • After two operations, the sequence is (1,2,5,9,7,3,5)(1,2,5,9,7,3,5).
  • After three operations, the sequence is (7,2,3,5,1,9,3)(7,2,3,5,1,9,3).

Sample Input 2

4 0
3 4 1 2
4 3 2 1

Sample Output 2

4 3 2 1

There may be cases where no operations are performed.

Sample Input 3

9 1000000000000000000
3 7 8 5 9 3 7 4 2
9 9 8 2 4 4 3 5 3

Sample Output 3

3 3 3 3 3 3 3 3 3