AtCoder Grand Contest 068
C
Ball Redistribution
AtCoder
⌀ 3182
原题
← BD →
翻译中…

Problem Statement

翻译中…

There are $N$ boxes numbered from $1$ to $N$, and $N$ balls numbered from $1$ to $N$.

翻译中…

You have assigned Snuke the following procedure as homework.

翻译中…
  • Put each ball into any box he likes. Multiple balls can be placed in the same box, and there can be boxes without balls.
  • For $i = 1, 2, \cdots, N$ in this order, perform the following operations.
  • If box $i$ contains no balls, do nothing.
    • If box $i$ contains balls, take all of them out and arrange them in a line in any order he likes. Let $k$ be the number of balls taken out, and $(x_1, x_2, \cdots, x_k)$ be the ball numbers in the line. For each $1 \leq j \leq k$, put ball $x_j$ into box $x_{j+1}$. Here, $x_{k+1}$ means $x_1$. All these operations of putting balls into boxes happen simultaneously.
翻译中…

He claims that he has completed the homework and reports the final state to you. Specifically, he says that ball $i$ is in box $A_i$ after the procedure.

翻译中…

You doubt whether he has correctly performed the procedure. Determine whether the state he reported is a possible result of the procedure.

翻译中…

There are $T$ test cases for each input.

翻译中…

Constraints

翻译中…
  • $1 \leq T \leq 250000$
  • $1 \leq N \leq 250000$
  • $1 \leq A_i \leq N$
  • The sum of $N$ over all test cases in each input is at most $250000$.
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
case_1
case_2
\vdots
case_T

翻译中…

Each test case is given in the following format:

翻译中…

N
A_1 A_2 \cdots A_N

翻译中…

Output

翻译中…

For each test case, print Yes if the state Snuke reported is a possible result of the procedure, and No otherwise.

翻译中…

样例

Input #1
5
3
1 1 1
3
2 2 2
5
1 2 3 4 5
10
8 3 8 10 1 5 3 1 6 4
10
1 5 1 2 4 8 8 6 7 3
Output #1
Yes
No
Yes
No
Yes
Consider the first test case. The following steps yield the state Snuke reported, so the answer is `Yes`. - Put balls $1, 2, 3$ into boxes $1, 1, 2$, respectively. - Take out the balls from box $1$ and arrange them as $(2, 1)$. - Put ball $2$ into box $1$. - Put ball $1$ into box $2$. - Take out the balls from box $2$ and arrange them as $(1, 3)$. - Put ball $1$ into box $3$. - Put ball $3$ into box $1$. - Take out the balls from box $3$ and arrange them as $(1)$. - Put ball $1$ into box $1$. - Now, balls $1, 2, 3$ are all in box $1$.
题目信息
题号
agc068_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。