创建于 2026/07/16 · 更新于 2026/07/16
You are given a permutation of length .
A subsequence of is obtained by deleting zero or more elements from without changing the order of the remaining elements.
A subsequence is called increasing if its elements are strictly increasing, and decreasing if its elements are strictly decreasing.
A longest increasing subsequence, abbreviated as LIS, is an increasing subsequence with the maximum possible length among all increasing subsequences of . Similarly, a longest decreasing subsequence, abbreviated as LDS, is a decreasing subsequence with the maximum possible length among all decreasing subsequences of .
Determine whether there exist an LIS and an LDS of such that they are disjoint, i.e. they do not use the same position of the original permutation.
The first line contains an integer (), the number of test cases.
Each test case consists of two lines.
The first line of each test case contains an integer (), the length of the permutation.
The second line contains integers (), forming a permutation of .
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output YES if there exist a longest increasing subsequence and a longest decreasing subsequence that are disjoint.
Otherwise, output NO.
You may print each letter in any case. For example, YES, Yes, and yes are all accepted.
6
1
1
4
2 4 1 3
4
2 1 4 3
5
1 2 3 4 5
5
5 4 3 2 1
8
3 7 1 5 8 2 6 4
NO
YES
NO
NO
NO
YES