310286: CF1810A. Beautiful Sequence

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Beautiful Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

A sequence of $m$ integers $a_{1}, a_{2}, \ldots, a_{m}$ is good, if and only if there exists at least one $i$ ($1 \le i \le m$) such that $a_{i} = i$. For example, $[3,2,3]$ is a good sequence, since $a_{2} = 2$, $a_{3} = 3$, while $[3,1,1]$ is not a good sequence, since there is no $i$ such that $a_{i} = 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.

Input

Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 500$) — the number of test cases. Their description follows.

The first line of each test case contains an integer $n$ ($1 \le n \le 100$) — the length of the given sequence.

The second line of each test case contains $n$ integers $a_{1}, a_{2}, \ldots, a_{n}$ ($1 \le a_{i} \le 10^9$), representing the sequence.

Output

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.

ExampleInput
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
Output
YES
YES
NO
YES
YES
NO
YES
Note

In the first test case, the good subsequence is $b=[3,2]$, where $b_{2} = 2$.

In the second test case, the good subsequence is $b=[2,4,3]$, where $b_{3} = 3$.

In the fourth test case, the good subsequence is $b=[1]$, where $b_{1} = 1$.

In the fifth test case, the good subsequence is $b=[2,2]$, where $b_{2} = 2$.

Input

题意翻译

一个长度为 $m$ 的序列 $a_1,a_2,\dots,a_m$ 被称为“好的”,当且仅当有至少一个 $i(1 \leq i \leq m)$ 使得 $a_i=i$。比如 $[3,2,3]$ 是一个“好的”序列,因为 $a_2=2$ 且 $a_3=3$;而 $[3,1.1]$ 不是一个“好的”序列。 而一个序列 $a$ 被称为“漂亮的”,当且仅当它有至少一个子序列是“好的”。比如 $[4,2,4]$ 是“漂亮的”,因为它的子序列 $[4,2]$ 是“好的”。 给定一个序列 $a$,求它是不是一个“漂亮的”序列。 多组数据,$t \leq 500$,$n \leq 100$,$1 \leq a_i \leq 10^9$。

Output

题目大意:
一个序列如果是好的,那么至少存在一个位置 i 使得 a_i = i。例如,[3,2,3] 是好的序列,因为 a_2 = 2 和 a_3 = 3,而 [3,1,1] 不是好的序列,因为没有 i 使得 a_i = i。

一个序列如果是漂亮的,那么至少存在一个子序列是好的。例如,[4,3,2] 是漂亮的序列,因为它的子序列 [4,2] 是好的,而 [5,3,4] 不是漂亮的序列。

序列 b 是序列 a 的子序列,如果 b 可以通过删除 a 中的几个(可能是零个或全部)元素得到。

现在给定一个序列,要检查它是否是漂亮的。

输入输出数据格式:
每个测试包含多个测试案例。第一行包含一个整数 t (1 ≤ t ≤ 500) —— 测试案例的数量。接下来是每个测试案例的描述。

每个测试案例的第一行包含一个整数 n (1 ≤ n ≤ 100) —— 给定序列的长度。

每个测试案例的第二行包含 n 个整数 a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9),代表序列。

对于每个测试案例,输出 "YES" 或 "NO"(不带引号),表示给定的序列是否是漂亮的。

输出答案时大小写不敏感。例如,"yEs"、"yes"、"Yes" 和 "YES" 都会被认为是肯定回答。

示例输入输出:
输入:
```
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
```
输出:
```
YES
YES
NO
YES
YES
NO
YES
```
注意:
- 在第一个测试案例中,好的子序列是 b=[3,2],其中 b_2 = 2。
- 在第二个测试案例中,好的子序列是 b=[2,4,3],其中 b_3 = 3。
- 在第四个测试案例中,好的子序列是 b=[1],其中 b_1 = 1。
- 在第五个测试案例中,好的子序列是 b=[2,2],其中 b_2 = 2。题目大意: 一个序列如果是好的,那么至少存在一个位置 i 使得 a_i = i。例如,[3,2,3] 是好的序列,因为 a_2 = 2 和 a_3 = 3,而 [3,1,1] 不是好的序列,因为没有 i 使得 a_i = i。 一个序列如果是漂亮的,那么至少存在一个子序列是好的。例如,[4,3,2] 是漂亮的序列,因为它的子序列 [4,2] 是好的,而 [5,3,4] 不是漂亮的序列。 序列 b 是序列 a 的子序列,如果 b 可以通过删除 a 中的几个(可能是零个或全部)元素得到。 现在给定一个序列,要检查它是否是漂亮的。 输入输出数据格式: 每个测试包含多个测试案例。第一行包含一个整数 t (1 ≤ t ≤ 500) —— 测试案例的数量。接下来是每个测试案例的描述。 每个测试案例的第一行包含一个整数 n (1 ≤ n ≤ 100) —— 给定序列的长度。 每个测试案例的第二行包含 n 个整数 a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9),代表序列。 对于每个测试案例,输出 "YES" 或 "NO"(不带引号),表示给定的序列是否是漂亮的。 输出答案时大小写不敏感。例如,"yEs"、"yes"、"Yes" 和 "YES" 都会被认为是肯定回答。 示例输入输出: 输入: ``` 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 ``` 输出: ``` YES YES NO YES YES NO YES ``` 注意: - 在第一个测试案例中,好的子序列是 b=[3,2],其中 b_2 = 2。 - 在第二个测试案例中,好的子序列是 b=[2,4,3],其中 b_3 = 3。 - 在第四个测试案例中,好的子序列是 b=[1],其中 b_1 = 1。 - 在第五个测试案例中,好的子序列是 b=[2,2],其中 b_2 = 2。

加入题单

上一题 下一题 算法标签: