CF1674D.A-B-C Sort
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given three arrays a , b and c . Initially, array a consists of n elements, arrays b and c are empty.
You are performing the following algorithm that consists of two steps:
- Step 1 : while a is not empty, you take the last element from a and move it in the middle of array b . If b currently has odd length, you can choose: place the element from a to the left or to the right of the middle element of b . As a result, a becomes empty and b consists of n elements.
- Step 2 : while b is not empty, you take the middle element from b and move it to the end of array c . If b currently has even length, you can choose which of two middle elements to take. As a result, b becomes empty and c now consists of n elements.
Refer to the Note section for examples.Can you make array c sorted in non-decreasing order?
输入格式
The first line contains a single integer t ( 1≤t≤2⋅104 ) — the number of test cases. Next t cases follow.
The first line of each test case contains the single integer n ( 1≤n≤2⋅105 ) — the length of array a .
The second line of each test case contains n integers a1,a2,…,an ( 1≤ai≤106 ) — the array a itself.
It's guaranteed that the sum of n doesn't exceed 2⋅105 .
输出格式
For each test, print YES (case-insensitive), if you can make array c sorted in non-decreasing order. Otherwise, print NO (case-insensitive).
输入输出样例
输入#1
3 4 3 1 5 3 3 3 2 1 1 7331
输出#1
YES NO YES
说明/提示
In the first test case, we can do the following for a=[3,1,5,3] :
Step 1 :
a [3,1,5,3] ⇒ [3,1,5] ⇒ [3,1] ⇒ [3] ⇒ []
b [] ⇒ [3] ⇒ [3,5] ⇒ [3,1,5] ⇒ [3,3,1,5]
Step 2 :
b [3,3,1,5] ⇒ [3,3,5] ⇒ [3,5] ⇒ [5] ⇒ []
c [] ⇒ [1] ⇒ [1,3] ⇒ [1,3,3] ⇒ [1,3,3,5]
As a result, array c=[1,3,3,5] and it's sorted.