Codeforces Round 1051 (Div. 2)
A
All Lengths Subtraction
Codeforces
800
原题
←B →
翻译中…

You are given a permutation$^{\text{∗}}$ $p$ of length $n$.

翻译中…

You must perform exactly one operation for each integer $k$ from 1 up to $n$ in that order:

翻译中…
  • Choose a subarray$^{\text{†}}$ of $p$ of length exactly $k$, and subtract 1 from every element in that subarray.
翻译中…

After completing all $n$ operations, your goal is to have all elements of the array equal to zero.

翻译中…

Determine whether it is possible to achieve this.

翻译中…

$^{\text{∗}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array). $^{\text{†}}$An array $a$ is a subarray of an array $b$ if $a$ can be obtained from $b$ by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). The description of the test cases follows.

翻译中…

The first line contains the value $n$ ($1 \leq n \leq 100$) — the length of the permutation.

翻译中…

The second line contains $p_1, p_2, \ldots p_n$ ($1 \le p_i \le n$) — the permutation itself.

翻译中…

Output

翻译中…

For each test case, output YES if it is possible to make all elements of the array $p$ equal to $0$ after performing all the operations; otherwise, output NO.

翻译中…

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.

翻译中…

Note

翻译中…

For the first test case, we can proceed as follows:

翻译中…
  • $k = 1$: Choose the subarray $[3, 3]$. The array $[1, 3, 4, 2]$ becomes $[1, 3, 3, 2]$.
  • $k = 2$: Choose the subarray $[2, 3]$. The array $[1, 3, 3, 2]$ becomes $[1, 2, 2, 2]$.
  • $k = 3$: Choose the subarray $[2, 4]$. The array $[1, 2, 2, 2]$ becomes $[1, 1, 1, 1]$.
  • $k = 4$: Choose the subarray $[1, 4]$. The array $[1, 1, 1, 1]$ becomes $[0, 0, 0, 0]$.
翻译中…

Thus, we have successfully reduced the entire array to zeros, so the answer is YES.

翻译中…

For the second test case, it can be shown that it is impossible to reduce all elements to zero.

翻译中…

For the third test case, the process is as follows:

翻译中…

$[2, 4, \boldsymbol{5}, 3, 1] \rightarrow [2, \boldsymbol{4, 4}, 3, 1] \rightarrow [2, \boldsymbol{3, 3, 3}, 1] \rightarrow [\boldsymbol{2, 2, 2, 2}, 1] \rightarrow [\boldsymbol{1, 1, 1, 1, 1}] \rightarrow [0, 0, 0, 0, 0].$

翻译中…

The bolded values indicate the subarrays from which we subtract at each step.

翻译中…

For the fourth test case, it can also be proven that it is impossible to make all values zero.

翻译中…

样例

Input #1
4
4
1 3 4 2
5
1 5 2 4 3
5
2 4 5 3 1
3
3 1 2
Output #1
YES
NO
YES
NO
InputCopy OutputCopy
题目信息
题号
2143A
时间限制
1 s
内存限制
256 MB
标签
暴力
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。