CF1810A.Beautiful Sequence
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A sequence of m integers a1,a2,…,am is good, if and only if there exists at least one i (1≤i≤m) such that ai=i. For example, [3,2,3] is a good sequence, since a2=2, a3=3, while [3,1,1] is not a good sequence, since there is no i such that ai=i.
A sequence a is beautiful, if and only if there exists at least one subsequence of a satisfying that this subsequence is good. For example, [4,3,2] is a beautiful sequence, since its subsequence [4,2] is good, while [5,3,4] is not a beautiful sequence.
A sequence b is a subsequence of a sequence a if b can be obtained from a by the deletion of several (possibly, zero or all) elements.
Now you are given a sequence, check whether it is beautiful or not.
一个由 m 个整数组成的序列 a1,a2,…,am 被称为好序列,当且仅当存在至少一个下标 i(其中 1≤i≤m),使得 ai=i。例如,[3,2,3] 是一个好序列,因为 a2=2 且 a3=3;而 [3,1,1] 不是好序列,因为不存在满足 ai=i 的下标 i。
一个序列 a 被称为优美序列,当且仅当它存在至少一个子序列,该子序列是好序列。例如,[4,3,2] 是一个优美序列,因为它的子序列 [4,2] 是好序列;而 [5,3,4] 不是优美序列。
序列 b 是序列 a 的一个子序列,当且仅当 b 可通过从 a 中删除若干(可能为零个或全部)元素得到。
现在给你一个序列,请判断它是否为优美序列。
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤500) — the number of test cases. Their description follows.
The first line of each test case contains an integer n (1≤n≤100) — the length of the given sequence.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109), representing the sequence.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤500),表示测试用例的数量。接下来是这些测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤100),表示给定序列的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109),表示该序列。
输出格式
For each test case, output "YES" or "NO"(without quotes) in one line, representing whether the given sequence is beautiful.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
对于每个测试用例,在一行中输出 “YES” 或 “NO”(不带引号),表示给定序列是否为优美序列。
您可以以任意大小写形式输出答案(大写或小写)。例如,字符串 “yEs”、“yes”、“Yes” 和 “YES” 均会被识别为肯定回答。
输入输出样例
输入#1
7 3 3 2 1 4 2 4 3 5 5 2 3 5 5 6 2 3 1 5 2 4 5 2 3 4 5 6 7 8 6 6 5 4 3 2 1
输出#1
YES YES NO YES YES NO YES
说明/提示
In the first test case, the good subsequence is b=[3,2], where b2=2.
In the second test case, the good subsequence is b=[2,4,3], where b3=3.
In the fourth test case, the good subsequence is b=[1], where b1=1.
In the fifth test case, the good subsequence is b=[2,2], where b2=2.
在第一个测试用例中,好的子序列为 b=[3,2],其中 b2=2。
在第二个测试用例中,好的子序列为 b=[2,4,3],其中 b3=3。
在第四个测试用例中,好的子序列为 b=[1],其中 b1=1。
在第五个测试用例中,好的子序列为 b=[2,2],其中 b2=2。
输入解题思路,AI测评打分。不知道怎么写?