CF2031B.Penchick and Satay Sticks

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

Penchick and Satay Sticks

Penchick and his friend Kohane are touring Indonesia, and their next stop is in Surabaya!

In the bustling food stalls of Surabaya, Kohane bought nn satay sticks and arranged them in a line, with the ii-th satay stick having length pip_i. It is given that pp is a permutation^{\text{∗}} of length nn.

Penchick wants to sort the satay sticks in increasing order of length, so that pi=ip_i=i for each 1in1\le i\le n. For fun, they created a rule: they can only swap neighboring satay sticks whose lengths differ by exactly 11. Formally, they can perform the following operation any number of times (including zero):

  • Select an index ii (1in11\le i\le n-1) such that pi+1pi=1|p_{i+1}-p_i|=1;
  • Swap pip_i and pi+1p_{i+1}.

Determine whether it is possible to sort the permutation pp, thus the satay sticks, by performing the above operation.

^{\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).

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t21051 \le t \le 2\cdot 10^5). The description of the test cases follows.

The first line of each test case contains a single integer nn (1n21051 \le n \le 2\cdot 10^5) — the number of satay sticks.

The second line of each test case contains nn integers p1,p2,,pnp_1, p_2, \ldots, p_n (1pin1 \le p_i \le n) — the permutation pp representing the length of the satay sticks.

It is guaranteed that the sum of nn over all test cases does not exceed 21052\cdot 10^5.

Output

For each test case, output "YES" if it is possible to sort permutation pp by performing the operation. 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

In the first test case, we can sort permutation p=[2,1,3,4]p = [2, 1, 3, 4] by performing an operation on index 11 (p2p1=12=1|p_2 - p_1| = |1 - 2| = 1), resulting in p=[1,2,3,4]p = [1, 2, 3, 4].

In the second test case, it can be proven that it is impossible to sort permutation p=[4,2,3,1]p = [4, 2, 3, 1] by performing the operation. Here is an example of a sequence of operations that can be performed on the permutation:

  • Select i=2i = 2 (p3p2=32=1|p_3 - p_2| = |3 - 2| = 1). This results in p=[4,3,2,1]p = [4, 3, 2, 1].
  • Select i=1i = 1 (p2p1=34=1|p_2 - p_1| = |3 - 4| = 1). This results in p=[3,4,2,1]p = [3, 4, 2, 1].
  • Select i=3i = 3 (p4p3=12=1|p_4 - p_3| = |1 - 2| = 1). This results in p=[3,4,1,2]p = [3, 4, 1, 2].

Unfortunately, permutation pp remains unsorted after performing the operations.

Samples

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

在线编程 IDE

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