CF2195B.Heapify 1

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

Heapify 1

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

You can perform the following operation any number of times (possibly zero):

  • Select an index ii (1in21 \le i \le \frac{n}{2}), and swap aia_i and a2ia_{2i}.

For example, when a=[1,4,2,3,5]a=[1,4,2,3,5], you can swap a2a_2 and a4a_4 to make it [1,3,2,4,5][1,3,2,4,5], but you cannot swap a2a_2 and a3a_3.

Please determine if the sequence aa can be sorted in increasing order.

^{\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 (1t1041 \le t \le 10^4). 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 second line of each test case contains nn distinct integers a1,a2,,ana_1,a_2,\ldots,a_n (1ain1 \le a_i \le n).

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

Output

If aa can be sorted in increasing order, output "YES" on a separate line. Otherwise, output "NO" on a separate line.

You can output the answer in any case. For example, the strings "yEs", "yes", and "Yes" will also be recognized as positive responses.

Note

In the first test case, aa is [1,4,3,2,5][1,4,3,2,5]. You can sort aa in increasing order by swapping a2a_2 and a4a_4. Therefore, the answer is "YES".

In the second test case, aa is [1,4,2,3,5][1,4,2,3,5]. It is impossible to sort aa in increasing order. Therefore, the answer is "NO".

Samples

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

在线编程 IDE

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