CF1197B.Pillars
入门
通过率:0%
时间限制:1.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n pillars aligned in a row and numbered from 1 to n.
Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai.
You can move these disks from one pillar to another. You can take a disk from pillar i and place it on top of pillar j if all these conditions are met:
- there is no other pillar between pillars i and j. Formally, it means that ∣i−j∣=1;
- pillar i contains exactly one disk;
- either pillar j contains no disks, or the topmost disk on pillar j has radius strictly greater than the radius of the disk you move.
When you place a disk on a pillar that already has some disks on it, you put the new disk on top of previously placed disks, so the new disk will be used to check the third condition if you try to place another disk on the same pillar.
You may take any disk and place it on other pillar any number of times, provided that every time you do it, all three aforementioned conditions are met. Now you wonder, is it possible to place all n disks on the same pillar simultaneously?
有 n 根柱子排成一行,编号从 1 到 n。
初始时,每根柱子上恰好放置一个圆盘。第 i 根柱子上的圆盘半径为 ai。
你可以将这些圆盘在柱子之间移动。你可以将柱子 i 上的圆盘取出,并将其放置到柱子 j 的顶部,当且仅当满足以下全部条件:
- 柱子 i 与柱子 j 之间没有其他柱子。形式化地说,即 ∣i−j∣=1;
- 柱子 i 上恰好只有一个圆盘;
- 柱子 j 上要么没有圆盘,要么其最上方的圆盘半径严格大于你所移动的圆盘的半径。
当你将一个圆盘放置到一根已有若干圆盘的柱子上时,新圆盘被置于所有已有圆盘的顶部,因此若之后尝试再向该柱子放置另一个圆盘,则需用这个新放置的圆盘来检验上述第三条条件。
你可以任意多次地取任一圆盘并将其放置到其他柱子上,只要每次操作均满足上述三条条件即可。现在你想知道:是否可能将全部 n 个圆盘同时放置到同一根柱子上?
输入格式
The first line contains one integer n (3≤n≤2⋅105) — the number of pillars.
The second line contains n integers a1, a2, ..., ai (1≤ai≤n), where ai is the radius of the disk initially placed on the i-th pillar. All numbers ai are distinct.
第一行包含一个整数 n(3≤n≤2⋅105)—— 表示柱子的数量。
第二行包含 n 个整数 a1, a2, ..., an(1≤ai≤n),其中 ai 表示初始时放置在第 i 根柱子上的圆盘的半径。所有 ai 均互不相同。
输出格式
Print YES if it is possible to place all the disks on the same pillar simultaneously, and NO otherwise. You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).
如果可以将所有圆盘同时放置在同一根柱子上,则输出 YES,否则输出 NO。每个字母的大小写不限(YES、yes、Yes 均被视为肯定回答;NO、no、nO 均被视为否定回答)。
输入输出样例
输入#1
4 1 3 4 2
输出#1
YES
输入#2
3 3 1 2
输出#2
NO
说明/提示
In the first case it is possible to place all disks on pillar 3 using the following sequence of actions:
- take the disk with radius 3 from pillar 2 and place it on top of pillar 3;
- take the disk with radius 1 from pillar 1 and place it on top of pillar 2;
- take the disk with radius 2 from pillar 4 and place it on top of pillar 3;
- take the disk with radius 1 from pillar 2 and place it on top of pillar 3.
在第一种情况下,可以按照以下操作序列将所有圆盘放置到第 3 根柱子上:
- 将半径为 3 的圆盘从第 2 根柱子上取下,并将其放置到第 3 根柱子的顶部;
- 将半径为 1 的圆盘从第 1 根柱子上取下,并将其放置到第 2 根柱子的顶部;
- 将半径为 2 的圆盘从第 4 根柱子上取下,并将其放置到第 3 根柱子的顶部;
- 将半径为 1 的圆盘从第 2 根柱子上取下,并将其放置到第 3 根柱子的顶部。
输入解题思路,AI测评打分。不知道怎么写?