Codeforces Round 1073 (Div. 2)
A
Array Coloring
Codeforces
800
原题
←B →
翻译中…

You have $n$ cards arranged in a row. The $i$-th card has the integer $a_i$ written on it. All integers are distinct.

翻译中…

You must color each card either $\color{red}{\text{red}}$ or $\color{blue}{\text{blue}}$ such that the following conditions are satisfied:

翻译中…
  • Any two adjacent cards in the row have different colors.
  • If you rearrange the cards so that the numbers on them are in increasing order, any two adjacent cards in the new row must also have different colors.
翻译中…

Determine if such a coloring exists.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains a single integer $n$ ($2 \le n \le 100$) — the length of the array.

翻译中…

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

翻译中…

It is guaranteed that all elements of $a$ are distinct.

翻译中…

Output

翻译中…

For each test case, output "YES" if you can color the cards so that the conditions are satisfied, and "NO" otherwise.

翻译中…

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

翻译中…

Note

翻译中…

In the first example, the cards are colored as $a = [\color{red}{2}, \color{blue}{3}, \color{red}{4}, \color{blue}{1}]$. After sorting, the cards become $[\color{blue}{1}, \color{red}{2}, \color{blue}{3}, \color{red}{4}]$. Both sequences satisfy the condition, so the answer is YES.

翻译中…

In the second example, no valid coloring exists. For instance, if we color the cards as $a = [\color{blue}{2}, \color{red}{3}, \color{blue}{1}]$, the sorted sequence becomes $[\color{blue}{1}, \color{blue}{2}, \color{red}{3}]$. Here, the adjacent elements $1$ and $2$ have the same color, so the condition is not satisfied.

翻译中…

In the third example, a possible coloring is $a = [\color{blue}{3}, \color{red}{4}, \color{blue}{1}, \color{red}{2}, \color{blue}{5}]$. After sorting, the cards become $[\color{blue}{1}, \color{red}{2}, \color{blue}{3}, \color{red}{4}, \color{blue}{5}]$.

翻译中…

样例

Input #1
4
4
2 3 4 1
3
2 3 1
5
3 4 1 2 5
5
3 1 4 2 5
Output #1
YES
NO
YES
NO
InputCopy OutputCopy
题目信息
题号
2191A
时间限制
1 s
内存限制
256 MB
标签
构造

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