第 1123 场 Codeforces Round(Div. 2)
D
后室山丘
Backrooms Hill
Codeforces
1400
原题
← CE →

后室山丘AI (CI翻译)

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\le k\le m$) such that the following conditions hold:

翻译中…
  • The first $k$ elements are strictly increasing. Formally, for all $i$ ($1\le i\lt k$), $b_i\lt b_{i+1}$.
  • The last $m-k+1$ elements are strictly decreasing. Formally, for all $i$ ($k\le i\lt m$), $b_i\gt b_{i+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\le i\le n-2$).
  • Swap $a_i$ and $a_{i+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.

翻译中…

Input

输入格式

AI (CI翻译)

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

每个测试包含多个测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^4$)。接下来描述各个测试用例。AI (CI翻译)

The first line of each test case contains an integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of array $a$.

每个测试用例的第一行包含一个整数 $n$($1\le n\le 2\cdot 10^5$),表示数组 $a$ 的长度。AI (CI翻译)

The second line of each test case contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ ($1\le a_i\le n$).

每个测试用例的第二行包含 $n$ 个互不相同的整数 $a_1, a_2, \ldots, a_n$($1\le a_i\le n$)。AI (CI翻译)

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

保证所有测试用例中 $n$ 的总和不超过 $2\cdot 10^5$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, print "YES" if it is possible to make array $a$ a hill. Otherwise, print "NO".

对于每个测试用例,如果可以将数组 $a$ 变成一座山丘,则输出“YES”;否则输出“NO”。AI (CI翻译)

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.

每个字母可以使用任意大小写(小写或大写)。例如,字符串“yEs”、“yes”、“Yes”和“YES”都会被接受为肯定回答。AI (CI翻译)

Note

说明

AI (CI翻译)

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 $a_1$ and $a_3$. After this operation, array $a$ becomes $[4, 3, 5, 6, 2, 1]$.
  • Swap $a_2$ and $a_4$. 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$ 已经是一座山丘。

在第三个测试用例中,可以按如下方式进行操作:

  • 交换 $a_1$ 和 $a_3$。操作后,数组 $a$ 变为 $[4, 3, 5, 6, 2, 1]$。
  • 交换 $a_2$ 和 $a_4$。操作后,数组 $a$ 变为 $[4, 6, 5, 3, 2, 1]$。

数组 $[4, 6, 5, 3, 2, 1]$ 是一座

山丘。AI (CI翻译)

样例

Input #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
Output #1
NO
YES
YES
NO
NO
YES
NO
InputCopy OutputCopy
题目信息
题号
2267D
时间限制
2 s
内存限制
256 MB
标签
构造
动态规划
贪心
排序
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。