310627: CF1862C. Flower City Fence

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Flower City Fencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Anya lives in the Flower City. By order of the city mayor, she has to build a fence for herself.

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 < j$.

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.

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.

On the left is the fence $[5, 4, 3, 2, 1]$, on the right is the same fence laid horizontally

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.

On the left is the fence $[4, 2, 1]$, on the right is the same fence laid horizontally

Help Anya and determine whether her fence is symmetrical.

Input

The first line of the input contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

The description of the test cases follows.

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.

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.

The sum of the values of $n$ for all test cases does not exceed $2 \cdot 10^5$.

Output

For each test case, output "YES" if the fence is symmetrical, otherwise output "NO".

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.

ExampleInput
7
5
5 4 3 2 1
3
3 1 1
3
4 2 1
1
2
5
5 3 3 1 1
5
5 5 5 3 3
2
6 1
Output
YES
YES
NO
NO
YES
YES
NO
Note

In the first and second test cases of the example, the fence is symmetrical.

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]$.

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]$.

In the fifth and sixth test cases of the example, the fence is symmetrical.

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]$.

Output

题目大意:
阿尼亚住在花城,她需要按照市长的命令为自己建造一堵围栏。围栏由n块木板组成,每块木板的高度为a_i米。根据命令,木板的高度不能增加,即对于所有i < j,都有a_i ≥ a_j。阿尼亚好奇她的围栏是否相对于对角线对称,换句话说,如果她将所有木板水平放置,顺序不变,是否会得到相同的围栏。

输入数据格式:
输入的第一行包含一个整数t(1 ≤ t ≤ 10^4)——测试用例的数量。
接下来是t个测试用例的描述。
每个测试用例的第一行包含一个整数n(1 ≤ n ≤ 2 × 10^5)——围栏的长度。
第二行包含n个整数a_1 ≥ a_2 ≥ a_3 ≥ … ≥ a_n(1 ≤ a_i ≤ 10^9)——木板的高度。
所有测试用例的n值之和不超过2 × 10^5。

输出数据格式:
对于每个测试用例,如果围栏是对称的,输出"YES",否则输出"NO"。
输出每个字母的大小写均可。例如,"yEs"、"yes"、"Yes"和"YES"都将被接受为肯定答案。题目大意: 阿尼亚住在花城,她需要按照市长的命令为自己建造一堵围栏。围栏由n块木板组成,每块木板的高度为a_i米。根据命令,木板的高度不能增加,即对于所有i < j,都有a_i ≥ a_j。阿尼亚好奇她的围栏是否相对于对角线对称,换句话说,如果她将所有木板水平放置,顺序不变,是否会得到相同的围栏。 输入数据格式: 输入的第一行包含一个整数t(1 ≤ t ≤ 10^4)——测试用例的数量。 接下来是t个测试用例的描述。 每个测试用例的第一行包含一个整数n(1 ≤ n ≤ 2 × 10^5)——围栏的长度。 第二行包含n个整数a_1 ≥ a_2 ≥ a_3 ≥ … ≥ a_n(1 ≤ a_i ≤ 10^9)——木板的高度。 所有测试用例的n值之和不超过2 × 10^5。 输出数据格式: 对于每个测试用例,如果围栏是对称的,输出"YES",否则输出"NO"。 输出每个字母的大小写均可。例如,"yEs"、"yes"、"Yes"和"YES"都将被接受为肯定答案。

加入题单

上一题 下一题 算法标签: