C. Element Extermination

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;

}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

秦三码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值