Codeforces Round #633 (Div. 2) C.Powered Addition

news/2025/3/25 13:27:46/

Codeforces Round #633 (Div. 2) C.Powered Addition

题目链接
You have an array a of length n. For every positive integer x you are going to perform the following operation during the x-th second:

  • Select some distinct indices i1,i2,…,ik which are between 1 and n inclusive, and add 2x−1 to each corresponding position of a. Formally, aij:=aij+2x−1 for j=1,2,…,k. Note that you are allowed to not select any indices at all.

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

Array a is nondecreasing if and only if a1≤a2≤…≤an.

You have to answer t independent test cases.

Input

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

The first line of each test case contains single integer n (1≤n≤1e5) — the length of array a. It is guaranteed that the sum of values of n over all test cases in the input does not exceed 105.

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

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

Example

input

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

output

2
0
3

遍历记录当前位置 i i i 之前的最大值 m a x max max,若该数 a i < m a x a_i<max ai<max,则需要改变的最小次数即为 m a x − a i max-a_i maxai 二进制位上1的最大位置,更新答案 a n s ans ans 即可,AC代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;int main(){int t;cin>>t;while(t--){int n;cin>>n;int a[n],mx=-1e9-5,ans=0,cnt=0;for(int i=0;i<n;i++) cin>>a[i];for(int i=0;i<n;i++){if(a[i]<mx){for(int j=31;j>=0;j--){if((1<<j)&(mx-a[i])){ans=max(ans,j+1);break;}}}mx=max(a[i],mx);}cout<<ans<<endl;}return 0;
}

http://www.ppmy.cn/news/712790.html

相关文章

ubuntu 20.04挂载ntfs磁盘

ubuntu 20.04挂载ntfs磁盘步骤如下&#xff1a; 查看当前用户id和组id&#xff0c;记下uid和gid id显示结果如下&#xff1a; uid1000(scue) gid1000(scue) 组1000(scue),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),109(lpadmin),124(sambashare),125(vboxusers),1001(u…

d3和弦图

效果图&#xff1a; 高亮效果&#xff1a; //chord.js,使用时直接引入&#xff0c;调用 //引入依赖d3,color.js是我自己的配色方案,可以直接使用d3的配色方案&#xff0c;例&#xff1a;d3.schemeSet3 define([d3.v5.min.js,../color.js,],function(d3,color){var relation…

Codeforces Round #833 (Div. 2)E. Yet Another Array Counting Problem(笛卡尔树+树形DP)

题目链接&#xff1a;Problem - E - Codeforces 样例输入&#xff1a; 4 3 3 1 3 2 4 2 2 2 2 2 6 9 6 9 6 9 6 9 9 100 10 40 20 20 100 60 80 60 60样例输出&#xff1a; 8 5 11880 351025663题意&#xff1a;给定一个长度为n的数组a[],对于每一个区间[l,r]&#xff0c;这个…

d313(d3131)

动车D313从苏州哪里&#xff1f;动车D313从苏州哪里坐 苏州火车南站 就是苏州新建的动车站 D313无锡到上海虹桥转乘D377上海虹桥到雁荡山&#xff01;1、问&#xff1a;D3? 换乘是要出站再进站的~ 北京至苏州D313次火车是在北京南站上车吗 北京——苏州&#xff1a;D313次动车…

MOOG伺服阀D633-7205

MOOG伺服阀D633-7205是一种节流控制阀&#xff0c;可应用于三通、四通和2*2通。具有快速性好、单位重量输出功率大、传动稳定、抗干扰能力强等特点。另一方面&#xff0c;在伺服系统中&#xff0c;传递信号和补偿特性时多使用电气部件。因此&#xff0c;现代高性能伺服系统都采…

第九届“互联网+”大赛产业赛道百度命题正式公布!57道命题,等你揭榜!

2023年6月28日&#xff0c;中国国际“互联网”大学生创新创业大赛组委会正式发布了《关于公布第九届中国国际“互联网”大学生创新创业大赛产业命题赛道入选命题的通知》&#xff0c;百度共有五十七道命题成功入围产业赛道&#xff0c;入围数居全国前列。 中国国际“互联网”大…

1759_C语言中冒泡排序的实现以及新编译环境测试

全部学习汇总&#xff1a; GreyZhang/c_basic: little bits of c. (github.com) 最近在重新学习C语言的数据结构&#xff0c;找了一份国外的电子书一点点看。刚刚学完双向链表&#xff0c;接下来的任务是搞定几个常用的排序。 冒泡排序还算是我比较熟悉的&#xff0c;工作之后…

5002 - git命令

git init git remote add origin https://gitee.com/xxxxx/zai-demo.git git add . git commit -m "添加注释信息" git push -u origin master -f --提交git rm -r --cache