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 bb consisting of mm integers is called a hill if there exists an index kk (1≤k≤m1\le k\le m) such that the following conditions hold:

  • The first kk elements are strictly increasing. Formally, for all ii (1≤i<k1\le i\lt k), bi<bi+1b_i\lt b_{i+1}.
  • The last m−k+1m-k+1 elements are strictly decreasing. Formally, for all ii (k≤i<mk\le i\lt m), bi>bi+1b_i\gt b_{i+1}.

You are given an array aa consisting of nn distinct integers. You may perform the following operation any number of times:

  • Choose any index ii (1≤i≤n−21\le i\le n-2).
  • Swap aia_i and ai+2a_{i+2} in the array.

Your task is to determine whether it is possible to turn array aa into a hill by performing the operation any number of times.

在格鲁吉亚(GR)市的居民中,流传着一个关于通往后台的山丘的传说。由 mm 个整数组成的数组 bb 被称为山丘(hill),当且仅当存在某个下标 kk(1≤k≤m1\le k\le m),使得以下条件成立:

  • 前 kk 个元素严格递增:即对所有 ii(1≤i<k1\le i\lt k),有 bi<bi+1b_i\lt b_{i+1};
  • 后 m−k+1m-k+1 个元素严格递减:即对所有 ii(k≤i<mk\le i\lt m),有 bi>bi+1b_i\gt b_{i+1}。

现给定一个由 nn 个互不相同的整数组成的数组 aa。你可以执行以下操作任意多次:

  • 任选一个下标 ii(1≤i≤n−21\le i\le n-2);
  • 交换数组中位置 ii 和 i+2i+2 上的元素(即交换 aia_i 与 ai+2a_{i+2})。

你的任务是判断:是否可以通过若干次上述操作,将数组 aa 变为一个山丘。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains an integer nn (1≤n≤2⋅1051\le n\le 2\cdot 10^5) — the length of array aa.

The second line of each test case contains nn distinct integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤n1\le a_i\le n).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052\cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051\le n\le 2\cdot 10^5)—— 数组 aa 的长度。

每个测试用例的第二行包含 nn 个互不相同的整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤n1\le a_i\le n)。

保证所有测试用例的 nn 之和不超过 2⋅1052\cdot 10^5。

输出格式

For each test case, print "YES" if it is possible to make array aa 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.

对于每个测试用例,如果可以将数组 aa 变为一座“山”,则输出 "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 aa into a hill.

In the second test case, array aa is already a hill.

In the third test case, you can perform the operations as follows:

  • Swap a1a_1 and a3a_3. After this operation, array aa becomes [4,3,5,6,2,1][4, 3, 5, 6, 2, 1].
  • Swap a2a_2 and a4a_4. After this operation, array aa becomes [4,6,5,3,2,1][4, 6, 5, 3, 2, 1].

And array [4,6,5,3,2,1][4, 6, 5, 3, 2, 1] is a hill.

在第一个测试用例中,无法将数组 aa 变为山形数组。

在第二个测试用例中,数组 aa 已经是山形数组。

在第三个测试用例中,你可以执行如下操作:

  • 交换 a1a_1 和 a3a_3。该操作后,数组 aa 变为 [4,3,5,6,2,1][4, 3, 5, 6, 2, 1]。
  • 交换 a2a_2 和 a4a_4。该操作后,数组 aa 变为 [4,6,5,3,2,1][4, 6, 5, 3, 2, 1]。

而数组 [4,6,5,3,2,1][4, 6, 5, 3, 2, 1] 是一个山形数组。

输入解题思路,AI测评打分。不知道怎么写?

首页