1862C.md (2948B)
1 Source: https://codeforces.com/problemset/problem/1862/C 2 3 C. Flower City Fence 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 Anya lives in the Flower City. By order of the city mayor, she has to build a fence for herself. 22 23 The fence consists of $n$ planks, each with a height of $a_i$ meters. According to the order, the heights of the planks must not increase. In other words, it is true that $a_i \ge a_j$ for all $i \lt j$. 24 25 Anya became curious whether her fence is symmetrical with respect to the diagonal. In other words, will she get the same fence if she lays all the planks horizontally in the same order. 26 27 For example, for $n = 5$, $a = [5, 4, 3, 2, 1]$, the fence is symmetrical. Because if all the planks are laid horizontally, the fence will be $[5, 4, 3, 2, 1]$, as shown in the diagram. 28 29  30 31 On the left is the fence $[5, 4, 3, 2, 1]$, on the right is the same fence laid horizontally 32 33 But for $n = 3$, $a = [4, 2, 1]$, the fence is not symmetrical. Because if all the planks are laid horizontally, the fence will be $[3, 2, 1, 1]$, as shown in the diagram. 34 35  36 37 On the left is the fence $[4, 2, 1]$, on the right is the same fence laid horizontally 38 39 Help Anya and determine whether her fence is symmetrical. 40 41 Input 42 43 The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases. 44 45 The description of the test cases follows. 46 47 The first line of a test case contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the fence. 48 49 The second line of a test case contains $n$ integers $a_1 \ge a_2 \ge a_3 \ge \dots \ge a_n$ ($1 \le a_i \le 10^9$) — the heights of the planks. 50 51 The sum of the values of $n$ for all test cases does not exceed $2 \cdot 10^5$. 52 53 Output 54 55 For each test case, output "YES" if the fence is symmetrical, otherwise output "NO". 56 57 You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes" and "YES" will be accepted as a positive answer. 58 59 Example 60 61 Input 62 63 ``` 64 7 65 66 5 67 68 5 4 3 2 1 69 70 3 71 72 3 1 1 73 74 3 75 76 4 2 1 77 78 1 79 80 2 81 82 5 83 84 5 3 3 1 1 85 86 5 87 88 5 5 5 3 3 89 90 2 91 92 6 1 93 ``` 94 95 Output 96 97 ``` 98 YES 99 YES 100 NO 101 NO 102 YES 103 YES 104 NO 105 ``` 106 107 Note 108 109 In the first and second test cases of the example, the fence is symmetrical. 110 111 In the third test case of the example, the fence is not symmetrical. If the planks are laid horizontally, the fence will be $[3, 2, 1, 1]$. 112 113 In the fourth test case of the example, the fence is not symmetrical. If the planks are laid horizontally, the fence will be $[1, 1]$. 114 115 In the fifth and sixth test cases of the example, the fence is symmetrical. 116 117 In the seventh test case of the example, the fence is not symmetrical. If the planks are laid horizontally, the fence will be $[2, 1, 1, 1, 1, 1]$.