Codeforces Round 771 (Div. 2)
B
Odd Swap Sort
Codeforces
1100
原题
← AC →
翻译中…

You are given an array $a_1, a_2, \dots, a_n$. You can perform operations on the array. In each operation you can choose an integer $i$ ($1 \le i \lt n$), and swap elements $a_i$ and $a_{i+1}$ of the array, if $a_i + a_{i+1}$ is odd.

翻译中…

Determine whether it can be sorted in non-decreasing order using this operation any number of times.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^5$) — the number of test cases. Description of the test cases follows.

翻译中…

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

翻译中…

The second line of each test case contains $n$ integers $a_1,a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array.

翻译中…

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

翻译中…

Output

翻译中…

For each test case, print "Yes" or "No" depending on whether you can or can not sort the given array.

翻译中…

You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).

翻译中…

Note

翻译中…

In the first test case, we can simply swap $31$ and $14$ ($31 + 14 = 45$ which is odd) and obtain the non-decreasing array $[1,6,14,31]$.

翻译中…

In the second test case, the only way we could sort the array is by swapping $4$ and $2$, but this is impossible, since their sum $4 + 2 = 6$ is even.

翻译中…

In the third test case, there is no way to make the array non-decreasing.

翻译中…

In the fourth test case, the array is already non-decreasing.

翻译中…

样例

Input #1
4
4
1 6 31 14
2
4 2
5
2 9 6 7 10
3
6 6 6
Output #1
Yes
No
No
Yes
InputCopy OutputCopy
题目信息
题号
1638B
时间限制
1 s
内存限制
256 MB
标签
数据结构
数学
排序

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