CF1338A.Powered Addition

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have an array aa of length nn. For every positive integer xx you are going to perform the following operation during the xx-th second:

  • Select some distinct indices i1,i2,…,iki_{1}, i_{2}, \ldots, i_{k} which are between 11 and nn inclusive, and add 2x−12^{x-1} to each corresponding position of aa. Formally, aij:=aij+2x−1a_{i_{j}} := a_{i_{j}} + 2^{x-1} for j=1,2,…,kj = 1, 2, \ldots, k. Note that you are allowed to not select any indices at all.

You have to make aa nondecreasing as fast as possible. Find the smallest number TT such that you can make the array nondecreasing after at most TT seconds.

Array aa is nondecreasing if and only if a1≤a2≤…≤ana_{1} \le a_{2} \le \ldots \le a_{n}.

You have to answer tt independent test cases.

你有一个长度为 nn 的数组 aa。对于每个正整数 xx,你将在第 xx 秒执行以下操作:

  • 选择若干互不相同的下标 i1,i2,…,iki_{1}, i_{2}, \ldots, i_{k},其中每个下标均在 11 到 nn 之间(含端点),并对数组 aa 中这些位置的元素各加上 2x−12^{x-1}。形式化地,对每个 j=1,2,…,kj = 1, 2, \ldots, k,执行 aij:=aij+2x−1a_{i_{j}} := a_{i_{j}} + 2^{x-1}。注意:你也可以不选择任何下标(即 k=0k = 0)。

你需要尽快使数组 aa 变为非递减序列。请找出最小的整数 TT,使得你能在至多 TT 秒内将该数组变为非递减序列。

数组 aa 是非递减的,当且仅当满足 a1≤a2≤…≤ana_{1} \le a_{2} \le \ldots \le a_{n}。

你需要回答 tt 个相互独立的测试用例。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^{4}) — the number of test cases.

The first line of each test case contains single integer nn (1≤n≤1051 \le n \le 10^{5}) — the length of array aa. It is guaranteed that the sum of values of nn over all test cases in the input does not exceed 10510^{5}.

The second line of each test case contains nn integers a1,a2,…,ana_{1}, a_{2}, \ldots, a_{n} (−109≤ai≤109-10^{9} \le a_{i} \le 10^{9}).

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^{4})—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^{5})—— 数组 aa 的长度。保证输入中所有测试用例的 nn 值之和不超过 10510^{5}。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_{1}, a_{2}, \ldots, a_{n}(−109≤ai≤109-10^{9} \le a_{i} \le 10^{9})。

输出格式

For each test case, print the minimum number of seconds in which you can make aa nondecreasing.

对于每个测试用例,输出使 aa 变为非递减序列所需的最少秒数。

输入输出样例

  • 输入#1

    3
    4
    1 7 6 5
    5
    1 2 3 4 5
    2
    0 -4

    输出#1

    2
    0
    3

说明/提示

In the first test case, if you select indices 3,43, 4 at the 11-st second and 44 at the 22-nd second, then aa will become [1,7,7,8][1, 7, 7, 8]. There are some other possible ways to make aa nondecreasing in 22 seconds, but you can't do it faster.

In the second test case, aa is already nondecreasing, so answer is 00.

In the third test case, if you do nothing at first 22 seconds and select index 22 at the 33-rd second, aa will become [0,0][0, 0].

在第一个测试用例中,若你在第 11 秒选择下标 3,43, 4,并在第 22 秒选择下标 44,则数组 aa 将变为 [1,7,7,8][1, 7, 7, 8]。还有其他一些在 22 秒内使 aa 变为非递减数组的方法,但无法更快完成。

在第二个测试用例中,aa 已经是非递减的,因此答案为 00。

在第三个测试用例中,若你在前 22 秒什么都不做,并在第 33 秒选择下标 22,则 aa 将变为 [0,0][0, 0]。

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

首页