2267D.md (2328B)
1 Source: https://codeforces.com/problemset/problem/2267/D 2 3 D. Backrooms Hill 4 5 time limit per test 6 7 2 seconds 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 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: 22 23 * The first $k$ elements are strictly increasing. Formally, for all $i$ ($1\le i\lt k$), $b_i\lt b_{i+1}$. 24 * The last $m-k+1$ elements are strictly decreasing. Formally, for all $i$ ($k\le i\lt m$), $b_i\gt b_{i+1}$. 25 26 You are given an array $a$ consisting of $n$ distinct integers. You may perform the following operation any number of times: 27 28 * Choose any index $i$ ($1\le i\le n-2$). 29 * Swap $a_i$ and $a_{i+2}$ in the array. 30 31 Your task is to determine whether it is possible to turn array $a$ into a hill by performing the operation any number of times. 32 33 Input 34 35 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. 36 37 The first line of each test case contains an integer $n$ ($1\le n\le 2\cdot 10^5$) — the length of array $a$. 38 39 The second line of each test case contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ ($1\le a_i\le n$). 40 41 It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot 10^5$. 42 43 Output 44 45 For each test case, print "YES" if it is possible to make array $a$ a hill. Otherwise, print "NO". 46 47 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. 48 49 Example 50 51 Input 52 53 ``` 54 7 55 56 3 57 58 2 1 3 59 60 4 61 62 1 2 3 4 63 64 6 65 66 5 3 4 6 2 1 67 68 6 69 70 1 5 2 3 6 4 71 72 7 73 74 1 2 3 4 7 5 6 75 76 5 77 78 5 4 1 3 2 79 80 6 81 82 4 1 3 2 6 5 83 ``` 84 85 Output 86 87 ``` 88 NO 89 90 YES 91 92 YES 93 94 NO 95 96 NO 97 98 YES 99 100 NO 101 ``` 102 103 Note 104 105 In the first test case, it is impossible to turn array $a$ into a hill. 106 107 In the second test case, array $a$ is already a hill. 108 109 In the third test case, you can perform the operations as follows: 110 111 * Swap $a_1$ and $a_3$. After this operation, array $a$ becomes $[4, 3, 5, 6, 2, 1]$. 112 * Swap $a_2$ and $a_4$. After this operation, array $a$ becomes $[4, 6, 5, 3, 2, 1]$. 113 114 And array $[4, 6, 5, 3, 2, 1]$ is a hill.