当前位置:网站首页>[codeforces] cf1338a - Powered addition [binary]
[codeforces] cf1338a - Powered addition [binary]
2022-07-03 02:09:00 【It's classmate Wang】
The question
Give a length of n ( n < = 100000 ) n ( n < = 100000 ) n(n<=100000) Array of , In the i i i Seconds can be arbitrarily selected to increase their value 2 i − 1 2^{i-1} 2i−1, Ask how many seconds it takes to make the array not decrement ?
Ideas
Traversal array , Maintain a prefix maximum , If at present a [ i ] < m a x c u r a[i]<max_{cur} a[i]<maxcur, Show the current a [ i ] a[i] a[i] It needs to be supplemented m a x c u r − a [ i ] max_{cur}-a[i] maxcur−a[i] size , And now a [ i ] a[i] a[i] Turn into m a x c u r max_{cur} maxcur, Last m a x ( m a x c u r − a [ i ] ) max(max_{cur}-a[i]) max(maxcur−a[i]) The binary digits of is the answer we require .
AC Code
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef long long ll;
typedef pair<int, int> p;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
int a[maxn];
int h[maxn];
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int t;
cin >> t;
while(t--){
int n;
cin >> n;
int max_cur = INT32_MIN;
int max_delta = INT32_MIN;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++){
if(a[i] > max_cur) max_cur = a[i];
else max_delta = max(max_delta, max_cur-a[i]);
}
if(max_delta==INT32_MIN) cout<<0<<endl;
else{
int cnt = 0;
while(max_delta) max_delta = max_delta >> 1, cnt++;
cout<<cnt<<endl;
}
}
return 0;
}
边栏推荐
- Redis: simple use of redis
- [shutter] hero animation (hero realizes radial animation | hero component createrecttween setting)
- His experience in choosing a startup company or a big Internet company may give you some inspiration
- 微信小程序开发工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理问题
- Cfdiv2 Fixed Point Guessing - (2 points for Interval answer)
- Ni visa fails after LabVIEW installs the third-party visa software
- Analysis, use and extension of open source API gateway apisex
- The Sandbox阐释对元宇宙平台的愿景
- 2022 spring "golden three silver four" job hopping prerequisites: Software Test interview questions (with answers)
- Where is the future of test engineers? Confused to see
猜你喜欢

Everything file search tool

全链路数字化转型下,零售企业如何打开第二增长曲线

【Camera专题】Camera dtsi 完全解析

Use go language to realize try{}catch{}finally

MySQL learning 03

《上市风云》荐书——唯勇气最可贵
![[shutter] hero animation (hero realizes radial animation | hero component createrecttween setting)](/img/e7/915404743d6639ac359bb4e7f7fbb7.jpg)
[shutter] hero animation (hero realizes radial animation | hero component createrecttween setting)

Recommendation letter of "listing situation" -- courage is the most valuable
![[camera topic] how to save OTP data in user-defined nodes](/img/3e/b76c4d6ef9ab5f5b4326a3a8aa1c4f.png)
[camera topic] how to save OTP data in user-defined nodes

Visual yolov5 format data set (labelme JSON file)
随机推荐
微信小程序開發工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理問題
DQL basic operation
What are the key points often asked in the redis interview
String replace space
树形结构数据的处理
easyPOI
stm32F407-------IIC通讯协议
Basic operation of view
Custom components, using NPM packages, global data sharing, subcontracting
DDL basic operation
Recommendation letter of "listing situation" -- courage is the most valuable
2022 spring "golden three silver four" job hopping prerequisites: Software Test interview questions (with answers)
深度学习笔记(持续更新中。。。)
File class (check)
[Yu Yue education] China Ocean University job search OMG reference
es6 filter() 数组过滤方法总结
Coroutinecontext in kotlin
A 30-year-old software tester, who has been unemployed for 4 months, is confused and doesn't know what to do?
创建+注册 子应用_定义路由,全局路由与子路由
Use go language to realize try{}catch{}finally