No.3529 2p Teleportations
タグ : / 解いたユーザー数 18
作問者 :
Germanium32
yt142857
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$.
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もしくは右上の雲マークをクリックしてアカウントを作成してください。