CF1891A Sorting with Twos
题目描述
给定一个长度为 $n$ 的序列 $a_1,a_2,.\ .\ .\ ,a_n$ 。在一次操作中,要求完成以下内容:
- 选择一个非负整数 $m$ ,要求 $2^m \le n$ 。
- 对于 $1 \le i \le 2^m$,将每个 $a_i$ 减去 $1$ 。
问:有没有一种方法,使的经过几次操作(可能 $0$ 次)的序列单调不减?
输入格式
第一行,一个正整数 $t \ (1 \le t \le 10^4)$ ,表示有 $t$ 组数据。
每组数据第一行,输入一个正整数 $n \ (1 \le n \le 20)$ ,表示序列 $a$ 的长度。
每组数据第二行,输入 $n$ 个数表示数列 $a \ (0 \le a_i \le 1000)$ 的元素。
输出格式
对于每组数据,输出一行一个 `YES` 表示此序列经过操作能单调不减,否则输出一行一个 `NO` 。
说明/提示
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 = 1 $ twice to get the array $ [4, 3, 3, 4, 4] $ . Then, we can choose $ m = 0 $ once and get the sorted in non-decreasing order array $ [3, 3, 3, 4, 4] $ .
In the third test case, we can choose $ m = 0 $ once and get the array $ [5, 5, 5, 7, 5, 6, 6, 8, 7] $ . Then, we can choose $ m = 2 $ twice and get the array $ [3, 3, 3, 5, 5, 6, 6, 8, 7] $ . After that, we can choose $ m = 3 $ once and get the sorted in non-decreasing order array $ [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.