CF1891A.Sorting with Twos

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 2m≤n2^m \leq n.
  • Subtract 11 from aia_i for all integers ii, such that 1≤i≤2m1 \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 ai≤ai+1a_i \leq a_{i + 1} for all integers ii such that 1≤i≤n−11 \leq i \leq n - 1.

给你一个整数数组 a1,a2,…,ana_1, a_2, \ldots, a_n。每次操作中,你需要执行以下步骤:

  • 选择一个非负整数 mm,使得 2m≤n2^m \leq n;
  • 对所有满足 1≤i≤2m1 \leq i \leq 2^m 的整数 ii,将 aia_i 减去 11。

你能否通过执行若干次(可能为零次)上述操作,将该数组变为非递减序列?

若对所有满足 1≤i≤n−11 \leq i \leq n - 1 的整数 ii,均有 ai≤ai+1a_i \leq a_{i + 1},则称该数组为非递减序列。

输入格式

The first line contains a single integer tt (1≤t≤1041 \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 (1≤n≤201 \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 (0≤ai≤10000 \leq a_i \leq 1000).

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)—— 测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤201 \leq n \leq 20)—— 数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n —— 数组 aa 中的整数(0≤ai≤10000 \leq a_i \leq 1000)。

输出格式

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

对于每个测试用例,如果数组可以被排序,则输出 “YES”,否则输出 “NO”。

输入输出样例

  • 输入#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

说明/提示

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.

在第一个测试用例中,数组已经按非递减顺序排序,因此我们无需执行任何操作。

在第二个测试用例中,我们可以选择 m=1m = 1 两次,得到数组 [4,3,3,4,4][4, 3, 3, 4, 4];然后选择 m=0m = 0 一次,得到按非递减顺序排序的数组 [3,3,3,4,4][3, 3, 3, 4, 4]。

在第三个测试用例中,我们可以选择 m=0m = 0 一次,得到数组 [5,5,5,7,5,6,6,8,7][5, 5, 5, 7, 5, 6, 6, 8, 7];然后选择 m=2m = 2 两次,得到数组 [3,3,3,5,5,6,6,8,7][3, 3, 3, 5, 5, 6, 6, 8, 7];接着选择 m=3m = 3 一次,得到按非递减顺序排序的数组 [2,2,2,4,4,5,5,7,7][2, 2, 2, 4, 4, 5, 5, 7, 7]。

对于第四和第五个测试用例,可以证明无法通过这些操作将数组排序。

输入解题思路,AI测评打分。不知道怎么写?

首页