AtCoder Grand Contest 031
D
A Sequence of Permutations
AtCoder
⌀ 2975
原题
← CE →
翻译中…

Problem Statement

翻译中…

For two permutations $p$ and $q$ of the integers from $1$ through $N$, let $f(p,q)$ be the permutation that satisfies the following:

翻译中…
  • The $p_i$-th element ($1 \leq i \leq N$) in $f(p,q)$ is $q_i$. Here, $p_i$ and $q_i$ respectively denote the $i$-th element in $p$ and $q$.
翻译中…

You are given two permutations $p$ and $q$ of the integers from $1$ through $N$. We will now define a sequence {$a_n$} of permutations of the integers from $1$ through $N$, as follows:

翻译中…
  • $a_1=p$, $a_2=q$
  • $a_{n+2}=f(a_n,a_{n+1})$ ( $n \geq 1$ )
翻译中…

Given a positive integer $K$, find $a_K$.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 10^5$
  • $1 \leq K \leq 10^9$
  • $p$ and $q$ are permutations of the integers from $1$ through $N$.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N K
p_1 ... p_N
q_1 ... q_N

翻译中…

Output

翻译中…

Print $N$ integers, with spaces in between. The $i$-th integer ($1 \leq i \leq N$) should be the $i$-th element in $a_K$.

翻译中…

样例

Input #1
3 3
1 2 3
3 2 1
Output #1
3 2 1
Since $a_3=f(p,q)$, we just need to find $f(p,q)$. We have $p_i=i$ here, so $f(p,q)=q$.
Input #2
5 5
4 5 1 2 3
3 2 1 5 4
Output #2
4 3 2 1 5
Input #3
10 1000000000
7 10 6 5 4 2 9 1 3 8
4 1 9 2 3 7 8 10 6 5
Output #3
7 9 4 8 2 5 1 6 10 3
题目信息
题号
agc031_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。