CF1891A.Sorting with Twos

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

Sorting with Twos

You are given an array of integers a1,a2,,ana_1, a_2, \ldots, a_n. In one operation, you do the following:

  • Choose a non-negative integer mm, such that 2mn2^m \leq n.
  • Subtract 11 from aia_i for all integers ii, such that 1i2m1 \leq i \leq 2^m.

Can you sort the array in non-decreasing order by performing some number (possibly zero) of operations?

An array is considered non-decreasing if aiai+1a_i \leq a_{i + 1} for all integers ii such that 1in11 \leq i \leq n - 1.

Input

The first line contains a single integer tt (1t1041 \leq t \leq 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1n201 \leq n \leq 20) — the length of array aa.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n — the integers in array aa (0ai10000 \leq a_i \leq 1000).

Output

For each test case, output "YES" if the array can be sorted, and "NO" otherwise.

Note

In the first test case, the array is already sorted in non-decreasing order, so we don't have to perform any operations.

In the second test case, we can choose m=1m = 1 twice to get the array [4,3,3,4,4][4, 3, 3, 4, 4]. Then, we can choose m=0m = 0 once and get the sorted in non-decreasing order array [3,3,3,4,4][3, 3, 3, 4, 4].

In the third test case, we can choose m=0m = 0 once and get the array [5,5,5,7,5,6,6,8,7][5, 5, 5, 7, 5, 6, 6, 8, 7]. Then, we can choose m=2m = 2 twice and get the array [3,3,3,5,5,6,6,8,7][3, 3, 3, 5, 5, 6, 6, 8, 7]. After that, we can choose m=3m = 3 once and get the sorted in non-decreasing order array [2,2,2,4,4,5,5,7,7][2, 2, 2, 4, 4, 5, 5, 7, 7].

For the fourth and fifth test case, it can be shown that the array could not be sorted using these operations.

Samples

8
5
1 2 3 4 5
5
6 5 3 4 4
9
6 5 5 7 5 6 6 8 7
4
4 3 2 1
6
2 2 4 5 3 2
8
1 3 17 19 27 57 179 13
5
3 17 57 179 92
10
1 2 3 4 0 6 7 8 9 10
YES
YES
YES
NO
NO
NO
YES
YES

在线编程 IDE

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