C. Element Extermination
C. Element Extermination
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given an array aa of length nn, which initially is a permutation of numbers from 11 to nn. In one operation, you can choose an index ii (1≤i<n1≤i<n) such that ai<ai+1ai<ai+1, and remove either aiai or ai+1ai+1 from the array (after the removal, the remaining parts are concatenated).
For example, if you have the array [1,3,2][1,3,2], you can choose i=1i=1 (since a1=1<a2=3a1=1<a2=3), then either remove a1a1 which gives the new array [3,2][3,2], or remove a2a2 which gives the new array [1,2][1,2].
Is it possible to make the length of this array equal to 11 with these operations?
Input
The first line contains a single integer tt (1≤t≤2⋅1041≤t≤2⋅104) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer nn (2≤n≤3⋅1052≤n≤3⋅105) — the length of the array.
The second line of each test case contains nn integers a1a1, a2a2, ..., anan (1≤ai≤n1≤ai≤n, aiai are pairwise distinct) — elements of the array.
It is guaranteed that the sum of nn over all test cases doesn't exceed 3⋅1053⋅105.
Output
For each test case, output on a single line the word "YES" if it is possible to reduce the array to a single element using the aforementioned operation, or "NO" if it is impossible to do so.
Example
input
Copy
4 3 1 2 3 4 3 1 2 4 3 2 3 1 6 2 4 6 1 3 5
output
Copy
YES YES NO YES
Note
For the first two test cases and the fourth test case, we can operate as follow (the bolded elements are the pair chosen for that operation):
[1,2,3]→[1,2]→[1][1,2,3]→[1,2]→[1]
[3,1,2,4]→[3,1,4]→[3,4]→[4][3,1,2,4]→[3,1,4]→[3,4]→[4]
[2,4,6,1,3,5]→[4,6,1,3,5]→[4,1,3,5]→[4,1,5]→[4,5]→[4][2,4,6,1,3,5]→[4,6,1,3,5]→[4,1,3,5]→[4,1,5]→[4,5]→[4]
=========================================================================
这种问题,下下策是用一天时间妄图用算法高级数据结构去解,下策是用半天模拟,中策是半小时证明,上策是写4的全部排列五分钟找出来规律
# include<iostream>
# include<string.h>
# include<vector>
using namespace std;
int main ()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int x,y;
cin>>x;
for(int i=1;i<n;i++)
{
cin>>y;
}
if(x>y)
{
cout<<"NO"<<endl;
}
else
cout<<"YES"<<endl;
}
return 0;
}