• 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

    For example, if you have the array [1,3,2][1,3,2], you can choose i=1i=1 (since a1=1

    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的全部排列五分钟找出来规律

    1. # include
    2. # include
    3. # include
    4. using namespace std;
    5. int main ()
    6. {
    7. int t;
    8. cin>>t;
    9. while(t--)
    10. {
    11. int n;
    12. cin>>n;
    13. int x,y;
    14. cin>>x;
    15. for(int i=1;i
    16. {
    17. cin>>y;
    18. }
    19. if(x>y)
    20. {
    21. cout<<"NO"<
    22. }
    23. else
    24. cout<<"YES"<
    25. }
    26. return 0;
    27. }

  • 相关阅读:
    嵌入式Linux入门-手把手教你初始化SDRAM(附代码)
    [附源码]SSM计算机毕业设计中青年健康管理监测系统JAVA
    深入理解Java多线程之线程间的通信方式(上)
    AOP介绍
    Java绘图-第19章
    Groovy之列表操作
    下一代英伟达H100 GPU发布时,国产芯片能追上吗?
    二十、java版 SpringCloud分布式微服务云架构之Java 异常处理
    超详细 | 鲸鱼优化算法原理及其实现(Matlab/Python)
    makefile的编写:由浅入深
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126250323