AtCoder Grand Contest 052
D
Equal LIS
AtCoder
⌀ 3304
原题
← CE →
翻译中…

Problem Statement

翻译中…

You are given a permutation $P_1, P_2, \dots, P_N$ of integers from $1$ to $N$. Is it possible to split it into $2$ subsequences, which have equal length of the Longest Increasing Subsequence?

翻译中…

Formally speaking, your goal is to get two integer sequences $a$ and $b$ such that:

翻译中…
  • Both $a$ and $b$ are subsequences of $P$.
  • Each integer $i=1,2,\cdots,N$ appears in exactly one of $a$ and $b$.
  • (The length of a longest increasing subsequence of $a$) $=$ (The length of a longest increasing subsequence of $b$)
翻译中…

Determine if the objective is achievable.

翻译中…

You will be given $T$ test cases. Solve each of them.

翻译中…

Constraints

翻译中…
  • $1 \le T \le 2 \cdot 10^5$
  • $1 \le N \le 2 \cdot 10^5$
  • $P_1, P_2, \dots, P_N$ is a permutation of integers from $1$ to $N$.
  • The sum of $N$ over all test cases doesn't exceed $2 \cdot 10^5$.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format. The first line of input is as follows:

翻译中…

T

翻译中…

Then, $T$ test cases follow, each of which is in the following format:

翻译中…

N
P_1 P_2 \dots P_N

翻译中…

Output

翻译中…

For each test case, print YES if it is possible to split the permutation into $2$ subsequences, which have equal length of the Longest Increasing Subsequence, and print NO otherwise. Use one line for each case. Note that the checker is case-insensitive: you can print letters in both uppercase and lowercase.

翻译中…

样例

Input #1
5
1
1
2
2 1
3
1 2 3
5
1 3 5 2 4
6
2 3 4 5 6 1
Output #1
NO
YES
NO
YES
NO
$[1, 3, 5, 2, 4]$ can be split into $[1, 5]$ and $[3, 2, 4]$, both have $LIS$ of length 2. It can be shown that there is no way to split $[2, 3, 4, 5, 6, 1]$ into $2$ subsequences with an equal length of $LIS$.
题目信息
题号
agc052_d
时间限制
2 s
内存限制
1024 MB

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