AtCoder Regular Contest 211 (Div. 2)
E
Greedy Takahashi 2
AtCoder
⌀ 3064
原题
← D→
翻译中…

Problem Statement

翻译中…

You are given a positive integer $N$ and a permutation $P$ of $(1,2,\dots,N)$.

翻译中…

When there is a tree with $N$ vertices numbered $1,2,\dots,N$, Snuke and Takahashi move according to the following rules:

翻译中…
  • Snuke specifies a permutation $Q$ of $(1,2,\dots,N)$ such that the sequence returned by Takahashi, when following the rules below, is lexicographically maximum.
  • Takahashi, who is at vertex $1$ of the tree, first receives $Q$ from Snuke and initializes an integer sequence $R$ with the length-$1$ sequence $(Q_1)$. Then, he moves $N-1$ times as follows, and returns the final $R$:
  • Visit the vertex $i$ with the smallest $Q_i$ among vertices that are adjacent to a previously visited vertex but have not yet been visited (it can be proved that there is always exactly one such vertex). Then, append $Q_i$ to the end of $R$.
翻译中…

Here, vertex $1$ is considered to have been visited initially.

翻译中…

Determine whether there exists a tree such that Takahashi returns $P$.

翻译中…

You are given $T$ test cases; solve each of them.

翻译中…

Constraints

翻译中…
  • $1 \le T \le 10^5$
  • $1 \le N \le 2 \times 10^5$
  • $P$ is a permutation of $(1,2,\dots,N)$.
  • The sum of $N$ over all test cases is at most $2 \times 10^5$.
  • All input values are integers.
翻译中…

Input

翻译中…

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

翻译中…

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

翻译中…

Each test case is given in the following format:

翻译中…

N
P_1 P_2 \ldots P_N

翻译中…

Output

翻译中…

Output $T$ lines.

翻译中…

The $i$-th line should contain Yes if there exists a tree satisfying the conditions for the $i$-th test case, and No otherwise.

翻译中…

样例

Input #1
3
4
4 2 3 1
4
4 1 3 2
11
11 8 9 6 7 10 3 4 5 1 2
Output #1
Yes
No
Yes
For the first test case, a tree with four vertices having edges between vertices $1$-$2$, $1$-$3$, and $2$-$4$ satisfies the conditions. If Snuke specifies $Q=(4,3,2,1)$, Takahashi visits vertices $1,3,2,4$ in this order and returns $R=(4,2,3,1)$. No matter what $Q$ Snuke specifies, it is impossible to make Takahashi return a sequence lexicographically larger than $(4,2,3,1)$, so the sequence that ends up being returned is $(4,2,3,1)$. For the second test case, it can be proved that there is no tree satisfying the conditions.
题目信息
题号
arc211_e
时间限制
2 s
内存限制
1024 MB

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