A. Powered Addition

滴答滴答--题目链接 

A. Powered Addition

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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,…,iki1,i2,…,ik which are between 11 and nn inclusive, and add 2x−12x−1 to each corresponding position of aa. Formally, aij:=aij+2x−1aij:=aij+2x−1 for j=1,2,…,kj=1,2,…,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≤…≤ana1≤a2≤…≤an.

You have to answer tt independent test cases.

Input

The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases.

The first line of each test case contains single integer nn (1≤n≤1051≤n≤105) — 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 105105.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (−109≤ai≤109−109≤ai≤109).

Output

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

Example

input

Copy

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

output

Copy

2
0
3

Note

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].

#include <bits/stdc++.h>
using namespace std;
const int maxn=100001;
typedef  long long  ll;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int a[maxn];
        for(int i=1; i<=n; i++)
            scanf("%d",&a[i]);
        int x=a[1];
        int k=0;
        for(int i=2; i<=n; i++)
        {
            x=max(x,a[i]);
            if(a[i]<x)
                k=max(k,x-a[i]);
        }
        if(k==0)
        {
            printf("0\n");
            continue;
        }
        int i=0;
        ll p=0;
        ll ans=0;
        for(i=1;; i++)
        {
            if(i==1)
                p=1;
            else
                p=p*2;
            ans+=p;
            if(ans>=k)
                break;
        }
        printf("%lld\n",i);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值