1545A.md (2140B)
1 Source: https://codeforces.com/problemset/problem/1545/A 2 3 A. AquaMoon and Strange Sort 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right. 22 23 AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa. 24 25 AquaMoon hopes that after some operations, the numbers written on the T-shirt of $n$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible. 26 27 Input 28 29 The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 50$) — the number of test cases. 30 31 The first line of each test case contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of Aquamoon's friends. 32 33 The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^5$) — the numbers, written on the T-shirts. 34 35 It is guaranteed that the sum of $n$ for all test cases does not exceed $10^5$. 36 37 Output 38 39 For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). 40 41 You can print each letter in any case (upper or lower). 42 43 Example 44 45 Input 46 47 ``` 48 3 49 4 50 4 3 2 5 51 4 52 3 3 2 2 53 5 54 1 2 3 5 4 55 ``` 56 57 Output 58 59 ``` 60 YES 61 YES 62 NO 63 ``` 64 65 Note 66 67 The possible list of operations in the first test case: 68 69 1. Swap $a_1$ and $a_2$. The resulting sequence is $3, 4, 2, 5$. The directions are: left, left, right, right. 70 2. Swap $a_2$ and $a_3$. The resulting sequence is $3, 2, 4, 5$. The directions are: left, left, right, right. 71 3. Swap $a_1$ and $a_2$. The resulting sequence is $2, 3, 4, 5$. The directions are: right, right, right, right.