| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 2048 MB | 18 | 8 | 8 | 44.444% |
Farmer John has an array $A$ containing $N$ integers ($1 \leq N \leq 5 \cdot 10^5, 1 \leq A_i \leq N$). He picks his favorite index $j$ and take out a sheet of paper with only $A_j$ written on it. He can then perform the following operation some number of times:
Let $S$ denote the set of distinct integers that occur in $A$. Farmer John wonders what the minimum number of operations he must perform is so that the paper contains all integers that appear in $S$.
Since it is unclear what FJ's favorite index is, output the answer for all possible favorite indices $1 \leq j \leq N$. Note for each index, $A$ is reset to its original form before performing any operations.
The first line contains $N$.
The following line contains $A_1, A_2, \ldots, A_N$.
Output $N$ space-separated integers, where the $i$'th integer is the answer for his favorite index $j = i$.
6 1 2 3 1 3 4
4 3 3 4 3 3
The distinct numbers are $S = \{ 1, 2, 3, 4 \}$. Suppose Farmer John’s favorite index is $j=1$. He starts off with $A_1=1$ written on a piece of paper. We can track the array $A$ after each cyclic shift Farmer John makes.
4 1 2 3 1 3
1 2 3 1 3 4
2 3 1 3 4 1
3 1 3 4 1 2
At this point, Farmer John has written down every number in $S$ using 4 operations.
12 1 1 2 1 1 3 1 1 4 1 1 1
8 7 6 7 8 9 8 7 6 7 8 9