当前位置:网站首页>[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;
}
边栏推荐
- [shutter] bottom navigation bar implementation (bottomnavigationbar bottom navigation bar | bottomnavigationbaritem navigation bar entry | pageview)
- y54.第三章 Kubernetes从入门到精通 -- ingress(二七)
- Unrecognized SSL message, plaintext connection?
- Startup mode and scope builder of collaboration in kotlin
- Hard core observation 547 large neural network may be beginning to become aware?
- 缺少库while loading shared libraries: libisl.so.15: cannot open shared object file: No such file
- Detailed introduction to the deployment and usage of the Nacos registry
- 各国Web3现状与未来
- 力扣(LeetCode)183. 从不订购的客户(2022.07.02)
- 机器学习笔记(持续更新中。。。)
猜你喜欢
[leetcode] 797 and 1189 (basis of graph theory)
Processing of tree structure data
In 2022, 95% of the three most common misunderstandings in software testing were recruited. Are you that 5%?
Deep learning notes (constantly updating...)
微信小程序開發工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理問題
stm32F407-------DMA
ByteDance data Lake integration practice based on Hudi
[camera topic] turn a drive to light up the camera
Visual yolov5 format data set (labelme JSON file)
The testing process that software testers should know
随机推荐
Network security - the simplest virus
Redis:Redis的简单使用
小程序开发黑马购物商城中遇到的问题
Network security - scan
Internal connection query and external connection
[Yu Yue education] Jiujiang University material analysis and testing technology reference
Kotlin middle process understanding and Practice (II)
Introduce in detail how to communicate with Huawei cloud IOT through mqtt protocol
Anna: Beibei, can you draw?
Return the only different value (de duplication)
In 2022, 95% of the three most common misunderstandings in software testing were recruited. Are you that 5%?
Technology sharing | Frida's powerful ability to realize hook functions
可視化yolov5格式數據集(labelme json文件)
[camera topic] complete analysis of camera dtsi
[shutter] pull the navigation bar sideways (drawer component | pageview component)
《上市风云》荐书——唯勇气最可贵
y54.第三章 Kubernetes从入门到精通 -- ingress(二七)
Y54. Chapter III kubernetes from introduction to mastery -- ingress (27)
How to find summer technical internship in junior year? Are you looking for a large company or a small company for technical internship?
深度(穿透)选择器 ::v-deep/deep/及 > > >