問題一覧 > 通常問題

No.3529 2p Teleportations

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 18
作問者 : GaLLium / テスター : Yoyoyo8128 yu23578 Germanium32 aa36 yt142857
お気に入りにしたユーザー ProblemId : 13233 / 自分の提出
問題文最終更新日: 2026-05-05 08:19:16
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
聖光学院プログラミングコンテスト2026 day2 (順位表) の他の問題:

Problem Statement

There are $N$ classrooms and $N$ students, each numbered from $1$ to $N$. Initially, student $i(1 \leq i \leq N)$ is in classroom $A_i$, and $(A_1,A_2,\ldots,A_N)$ is a permutation of $(1,2,\ldots,N)$. You are given $N,A,$ and a prime number greater than $\color{red}{N}$, denoted by $p$. Construct $1$ sequence $B$ that satisfies all of the following. (It is guaranteed that such a sequence always exists.)

  • $B$ is an integer sequence of length $N$, and $1 \leq B_i \leq N$ holds for $i=1,2,\ldots ,N$.
  • After repeating the following $\color{red}{2p}$ times, the number of $i(1 \leq i \leq N)$ such that student $i$ is not in classroom $i$ is less than $\sqrt{N}$.
    • For all $i=1,2,\ldots,N$, if student $i$ is in classroom $j$, teleport the student to classroom $B_j$.
You are given $T$ test cases. Find the answer for each of them.

Constraints

  • All input values are integers
  • $1 \leq T \leq 100$
  • $2 \leq N \leq 10^4$
  • $N \lt p \leq 2 \times 10^4$
  • $(A_1,A_2,\ldots,A_N)$ is a permutation of $(1,2,\ldots,N)$

Input

$T$
$\mathrm{case}_1$
$\mathrm{case}_2$
$\vdots$
$\mathrm{case}_T$
Here, $\mathrm{case}_t$ is the $t$-th test case, given in the following format.
$N\ p$
$A_1\ A_2\ \ldots\ A_N$

Output

Print $T$ lines. On the $t(1 \leq t \leq T)$-th line, print the sequence $B_1,B_2,\ldots,B_N$ for the $t$-th test case, separated by spaces.

Sample

Sample 1
Input
2
3 5
2 1 3
5 7
1 3 2 4 5
Output
1 1 3
1 2 2 4 5

For test case $1$, after all students have finished $2p = 10$ teleportations, students $1,2,3$ are in classrooms $1,1,3$, respectively. The number of $i$ such that student $i$ is not in classroom $i$ is $1$, with $i=2$ being the only one. This is less than $\sqrt{3}$, so the condition is satisfied. You will get AC by printing any $B$ that satisfies the conditions.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。