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 output Copy 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的全部排列五分钟找出来规律
4
3
1 2 3
4
3 1 2 4
3
2 3 1
6
2 4 6 1 3 5
YES
YES
NO
YES
[附源码]SSM计算机毕业设计中青年健康管理监测系统JAVA
深入理解Java多线程之线程间的通信方式(上)
AOP介绍
Java绘图-第19章
Groovy之列表操作
下一代英伟达H100 GPU发布时,国产芯片能追上吗?
二十、java版 SpringCloud分布式微服务云架构之Java 异常处理
超详细 | 鲸鱼优化算法原理及其实现(Matlab/Python)
makefile的编写:由浅入深