zoukankan      html  css  js  c++  java
  • A. Powered Addition

    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 2x12x−1 to each corresponding position of aa. Formally, aij:=aij+2x1aij:=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 a1a2ana1≤a2≤…≤an.

    You have to answer tt independent test cases.

    Input

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

    The first line of each test case contains single integer nn (1n1051≤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 (109ai109−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>
    #define ll              long long
    #define PII             pair<int, int>
    #define rep(i,a,b)      for(int  i=a;i<=b;i++)
    #define dec(i,a,b)      for(int  i=a;i>=b;i--)
    using namespace std;
    int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979323846;
    const int mod = 998244353;
    const int N = 1e5+5;
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    ll gcd(ll m, ll n)
    {
        return n == 0 ? m : gcd(n, m%n);
    }
    ll lcm(ll m, ll n)
    {
        return m*n / gcd(m, n);
    }
    bool cmp(PII a, PII b)
    {
        return a.second<b.second;
    }
    int main() {
        int T;
        cin>>T;
        vector<ll> b(33,1);
        rep(i,1,32)
        {
            b[i]=b[i-1]*2;
        }
    
        while(T--)
        {
            int n;
            cin>>n;
            vector<int> a(n+1);
            rep(i,1,n)
            {
                cin>>a[i];
            }
            ll d=0,maxn=a[1];
            rep(i,1,n)
            {
                if(d<maxn-a[i])
                    d=maxn-a[i];
                if(maxn<a[i])
                    maxn=a[i];
            }
            int res=upper_bound(b.begin(),b.end(),d)-b.begin();
            cout<<res<<endl;
        }
        return 0;
    }
  • 相关阅读:
    #2051:Bitset(进制转化)
    #2054:A == B ?(水题坑人)
    #2045:不容易系列之三LELE的RPG难题(dp递推)
    #2037:今年暑假不AC
    #2036:改革春风吹满地
    OJ中的语言选项里G++ 与 C++的区别
    如何在CSDN上如何快速转载博客
    Python之路(第八篇)Python内置函数、zip()、max()、min()
    Python编程笔记(第一篇)Python基础语法
    Python之路(第七篇)Python作用域、匿名函数、函数式编程、map函数、filter函数、reduce函数
  • 原文地址:https://www.cnblogs.com/dealer/p/12915125.html
Copyright © 2011-2022 走看看