题库练习 Sorting with Twos
← 上一题 下一题 →

A16348 | Sorting with Twos

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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

- Choose a non-negative integer $m$ , such that $2^m \leq n$ .
- Subtract $1$ from $a_i$ for all integers $i$ , such that $1 \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 $a_i \leq a_{i + 1}$ for all integers $i$ such that $1 \leq i \leq n - 1$ .

输入格式

The first line contains a single integer $t$ ( $1 \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 $n$ ( $1 \leq n \leq 20$ ) — the length of array $a$ .

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ — the integers in array $a$ ( $0 \leq a_i \leq 1000$ ).

输出格式

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

输入输出样例

输入 #1
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
输出 #1
YES
YES
YES
NO
NO
NO
YES
YES
C++ 编辑器
输入
输出