A16095 | Flower City Fence
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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$ .
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$ .
输出格式
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.
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]$ .
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]$ .
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]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted