CF1862C.Flower City Fence

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

The fence consists of nn planks, each with a height of aia_i meters. According to the order, the heights of the planks must not increase. In other words, it is true that aiaja_i \ge a_j for all i<ji < 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=5n = 5 , a=[5,4,3,2,1]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][5, 4, 3, 2, 1] , as shown in the diagram.

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

But for n=3n = 3 , a=[4,2,1]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][3, 2, 1, 1] , as shown in the diagram.

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

Help Anya and determine whether her fence is symmetrical.

输入格式

The first line of the input contains an integer tt ( 1t1041 \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 nn ( 1n21051 \le n \le 2 \cdot 10^5 ) — the length of the fence.

The second line of a test case contains nn integers a1a2a3ana_1 \ge a_2 \ge a_3 \ge \dots \ge a_n ( 1ai1091 \le a_i \le 10^9 ) — the heights of the planks.

The sum of the values of nn for all test cases does not exceed 21052 \cdot 10^5 .

输出格式

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.

输入输出样例

  • 输入#1

    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

    输出#1

    YES
    YES
    NO
    NO
    YES
    YES
    NO

说明/提示

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][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][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][2, 1, 1, 1, 1, 1] .

首页