CF2143A.All Lengths Subtraction

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

All Lengths Subtraction

You are given a permutation^{\text{∗}} pp of length nn.

You must perform exactly one operation for each integer kk from 1 up to nn in that order:

  • Choose a subarray^{\text{†}} of pp of length exactly kk, and subtract 1 from every element in that subarray.

After completing all nn 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 nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

^{\text{†}}An array aa is a subarray of an array bb if aa can be obtained from bb 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 tt (1t1001 \le t \le 100). The description of the test cases follows.

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

The second line contains p1,p2,pnp_1, p_2, \ldots p_n (1pin1 \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 pp equal to 00 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=1k = 1: Choose the subarray [3,3][3, 3]. The array [1,3,4,2][1, 3, 4, 2] becomes [1,3,3,2][1, 3, 3, 2].
  • k=2k = 2: Choose the subarray [2,3][2, 3]. The array [1,3,3,2][1, 3, 3, 2] becomes [1,2,2,2][1, 2, 2, 2].
  • k=3k = 3: Choose the subarray [2,4][2, 4]. The array [1,2,2,2][1, 2, 2, 2] becomes [1,1,1,1][1, 1, 1, 1].
  • k=4k = 4: Choose the subarray [1,4][1, 4]. The array [1,1,1,1][1, 1, 1, 1] becomes [0,0,0,0][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.

Samples

4
4
1 3 4 2
5
1 5 2 4 3
5
2 4 5 3 1
3
3 1 2
YES
NO
YES
NO

在线编程 IDE

建议全屏模式获得最佳体验