CF2267D.Backrooms Hill
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Among the people from the city GR, there is a legend about a hill that leads to the backstage. An array b consisting of m integers is called a hill if there exists an index k (1≤k≤m) such that the following conditions hold:
- The first k elements are strictly increasing. Formally, for all i (1≤i<k), bi<bi+1.
- The last m−k+1 elements are strictly decreasing. Formally, for all i (k≤i<m), bi>bi+1.
You are given an array a consisting of n distinct integers. You may perform the following operation any number of times:
- Choose any index i (1≤i≤n−2).
- Swap ai and ai+2 in the array.
Your task is to determine whether it is possible to turn array a into a hill by performing the operation any number of times.
在格鲁吉亚(GR)市的居民中,流传着一个关于通往后台的山丘的传说。由 m 个整数组成的数组 b 被称为山丘(hill),当且仅当存在某个下标 k(1≤k≤m),使得以下条件成立:
- 前 k 个元素严格递增:即对所有 i(1≤i<k),有 bi<bi+1;
- 后 m−k+1 个元素严格递减:即对所有 i(k≤i<m),有 bi>bi+1。
现给定一个由 n 个互不相同的整数组成的数组 a。你可以执行以下操作任意多次:
- 任选一个下标 i(1≤i≤n−2);
- 交换数组中位置 i 和 i+2 上的元素(即交换 ai 与 ai+2)。
你的任务是判断:是否可以通过若干次上述操作,将数组 a 变为一个山丘。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains an integer n (1≤n≤2⋅105) — the length of array a.
The second line of each test case contains n distinct integers a1,a2,…,an (1≤ai≤n).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 数组 a 的长度。
每个测试用例的第二行包含 n 个互不相同的整数 a1,a2,…,an(1≤ai≤n)。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, print "YES" if it is possible to make array a a hill. Otherwise, print "NO".
You may print each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as positive answers.
对于每个测试用例,如果可以将数组 a 变为一座“山”,则输出 "YES";否则输出 "NO"。
你可以以任意大小写形式输出每个字母(小写或大写)。例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均被视为有效的肯定回答。
输入输出样例
输入#1
7 3 2 1 3 4 1 2 3 4 6 5 3 4 6 2 1 6 1 5 2 3 6 4 7 1 2 3 4 7 5 6 5 5 4 1 3 2 6 4 1 3 2 6 5
输出#1
NO YES YES NO NO YES NO
说明/提示
In the first test case, it is impossible to turn array a into a hill.
In the second test case, array a is already a hill.
In the third test case, you can perform the operations as follows:
- Swap a1 and a3. After this operation, array a becomes [4,3,5,6,2,1].
- Swap a2 and a4. After this operation, array a becomes [4,6,5,3,2,1].
And array [4,6,5,3,2,1] is a hill.
在第一个测试用例中,无法将数组 a 变为山形数组。
在第二个测试用例中,数组 a 已经是山形数组。
在第三个测试用例中,你可以执行如下操作:
- 交换 a1 和 a3。该操作后,数组 a 变为 [4,3,5,6,2,1]。
- 交换 a2 和 a4。该操作后,数组 a 变为 [4,6,5,3,2,1]。
而数组 [4,6,5,3,2,1] 是一个山形数组。
输入解题思路,AI测评打分。不知道怎么写?