QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#842. 精灵之环

統計

在 C 部落,每 5 年就会举行一次大型的祭祀活动,大祭司会在远古符阵上念动真言,召唤出 $n$ 个位置的小精灵,小精灵会沿着符阵的指向进行快速跃动。

在符阵的每一个位置,都有一个符号指向着另一个位置。小精灵就会在下一个时刻跳到对应的位置,然后再下一个时刻又会随着到达的位置上的指向来跳动。小精灵肯定不会撞到一起,这意味着任何两个位置都不会指向一个位置。

形式化地,如果一个位置 $i$ 的符号指向 $f(i)$,那么小精灵经过 $k$ 个时刻后到达的位置是 $f_k(i) = f(f_{k-1}(i))$,而 $f_0(i) = i$。

曾经在那里考察的人类学家 Z. Jack 记载道:“C 部落的族人相信能在精灵的奇怪舞蹈中预言未来将要发生的事。”并且留下了一张当时的照片,记载了这一壮观的场面。

然而,文明社会的战争打扰了 C 部落的和平,炮火摧毁了曾经的符阵。50 年后,C 部落的人拜托你来复原符阵,但照片上的符文也模糊不清了。

仅剩的线索只有几个,曾经的祭司告诉了你,这张照片是在仪式开始第 $k$ 个时刻拍摄的。照片上标记了每个精灵在最初来自哪里。

祭司的记忆是准确的,Z. Jack 的记载也没有差错,所以你肯定能够找到一种可能的最初的符阵。

输入格式

第一行两个整数 $n, k$,表示符阵中小精灵位置的数量以及仪式进行的时间。

接下来一行 $n$ 个整数 $1 \le p_i \le n$,表示在此时原本在 $i$ 位置的精灵到达了 $p_i$ 位置。保证对于 $i \neq j$,有 $p_i \neq p_j$。

输出格式

输出一行 $n$ 个数,表示原本的符阵。

注意到合法的答案可能有多种,你只需要输出其中任意一种

样例数据

样例 1 输入

2 2
1 2

样例 1 输出

2 1

样例 2 输入

10 997
9 7 2 4 10 1 8 3 6 5

样例 2 输出

9 7 2 4 10 1 8 3 6 5

样例 3

见下发文件。

样例 4

见下发文件。

子任务

测试点 $n$ $k$ 特殊限制
$1 \sim 3$ $\leq 10$ $k\leq 10$
$4 \sim 5$ $\leq 2 \times 10^5$
$6$ $\leq 10^5$ $=2$
$7 \sim 8$ $=3$
$9 \sim 12$ $\leq 2 \times 10^5$ $k$ 是质数
$13 \sim 15$ 当 $i \ne n$ 时 $p_i = i+1$, $p_n = 1$
$16 \sim 20$

对于 $100\%$ 的数据,保证 $n \le 10^5$, $2 \le k \le 2 \times 10^5$

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.