CF2191A.Array Coloring

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Array Coloring

You have nn cards arranged in a row. The ii-th card has the integer aia_i written on it. All integers are distinct.

You must color each card either red\color{red}{\text{red}} or blue\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 tt (1t2001 \le t \le 200). The description of the test cases follows.

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

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

It is guaranteed that all elements of aa 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 [1,2,3][\color{blue}{1}, \color{blue}{2}, \color{red}{3}]. Here, the adjacent elements 11 and 22 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}]$.

Samples

4
4
2 3 4 1
3
2 3 1
5
3 4 1 2 5
5
3 1 4 2 5
YES
NO
YES
NO

在线编程 IDE

建议全屏模式获得最佳体验