CF1862C.Flower City Fence

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

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 ai≥aja_i \ge a_j for all i<ji \lt 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.

安雅住在花城。根据市长的命令,她必须为自己建造一道栅栏。

这道栅栏由 nn 块木板组成,每块木板的高度为 aia_i 米。根据命令,木板的高度不得递增。换言之,对所有 i<ji < j,均有 ai≥aja_i \ge a_j 成立。

安雅好奇她的栅栏是否关于主对角线对称。换句话说,若将所有木板按相同顺序水平放置,所得栅栏是否与原栅栏完全相同。

例如,当 n=5n = 5、a=[5,4,3,2,1]a = [5, 4, 3, 2, 1] 时,该栅栏是对称的。因为若将所有木板水平放置,所得栅栏仍为 [5,4,3,2,1][5, 4, 3, 2, 1],如图所示。

左侧为栅栏 [5,4,3,2,1][5, 4, 3, 2, 1],右侧为同一栅栏水平放置后的形态。

但当 n=3n = 3、a=[4,2,1]a = [4, 2, 1] 时,该栅栏不对称。因为若将所有木板水平放置,所得栅栏为 [3,2,1,1][3, 2, 1, 1],如图所示。

左侧为栅栏 [4,2,1][4, 2, 1],右侧为同一栅栏水平放置后的形态。

请帮助安雅判断她的栅栏是否对称。

输入格式

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

The second line of a test case contains nn integers a1≥a2≥a3≥⋯≥ana_1 \ge a_2 \ge a_3 \ge \dots \ge a_n (1≤ai≤1091 \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 2⋅1052 \cdot 10^5.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

接下来是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 表示篱笆的长度。

每个测试用例的第二行包含 nn 个整数 a1≥a2≥a3≥⋯≥ana_1 \ge a_2 \ge a_3 \ge \dots \ge a_n(1≤ai≤1091 \le a_i \le 10^9)—— 表示木板的高度。

所有测试用例的 nn 值之和不超过 2⋅1052 \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.

对于每个测试用例,如果栅栏是对称的,则输出 “YES”,否则输出 “NO”。

你可以以任意大小写形式输出每个字母(小写或大写)。例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均会被接受为肯定回答。

输入输出样例

  • 输入#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].

在示例的第一和第二个测试用例中,围栏是对称的。

在示例的第三个测试用例中,围栏不是对称的。如果木板水平放置,围栏将为 [3,2,1,1][3, 2, 1, 1]。

在示例的第四个测试用例中,围栏不是对称的。如果木板水平放置,围栏将为 [1,1][1, 1]。

在示例的第五和第六个测试用例中,围栏是对称的。

在示例的第七个测试用例中,围栏不是对称的。如果木板水平放置,围栏将为 [2,1,1,1,1,1][2, 1, 1, 1, 1, 1]。

输入解题思路,AI测评打分。不知道怎么写?

首页