QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 32 MB 満点: 100

#14185. 洗牌

統計

Byteasar 有一叠共 $n$ 张牌,他喜欢洗牌。牌的位置从 $1$ 到 $n$ 编号。Byteasar 掌握了高超的洗牌技巧,以至于每次洗牌他都能得到相同的排列,即第 $k$($1 \le k \le n$)个位置上的牌总是移动到相同的第 $a_k$ 个位置。我们用 $b_k$ 表示在 Byteasar 重复洗牌 $l$ 次后,第 $k$ 张牌(即最初放在第 $k$ 个位置上的牌)所处的位置。

任务

写一个程序:

  • 从标准输入读取整数 $n$ 和 $l$ 以及数列 $(b_k)$,
  • 确定数列 $(a_k)$,
  • 将该数列写入标准输出。

输入格式

第一行包含两个正整数 $n$ 和 $l$($1 \le n, l \le 1\,000\,000$)。

接下来的 $n$ 行中,每行包含数列 $(b_k)$ 的一个元素。第 $k+1$ 行包含一个正整数 $b_k$,表示最初处于第 $k$ 个位置的牌的最终位置($1 \le b_k \le n$)。

输出格式

输出 $n$ 个整数,每行一个,表示数列 $(a_k)$ 的连续元素。

第 $k$ 行应包含一个整数 $a_k$,表示最初处于第 $k$ 个位置的牌在进行一次洗牌后的位置。

你可以假设对于测试数据,总是存在满足要求的数列 $(a_k)$。如果存在多个这样的数列,你的程序应当输出其中任意一个。

样例

输入样例 1

5 2
1
2
5
3
4

输出样例 1

1
2
4
5
3

输入样例 2

5 2
1
2
5
3
4

输出样例 2

2
1
4
5
3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.