当前位置:网站首页>[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;
}
边栏推荐
- [fluent] hero animation (hero animation use process | create hero animation core components | create source page | create destination page | page Jump)
- Comment communiquer avec Huawei Cloud IOT via le Protocole mqtt
- Network security - Trojan horse
- 深度(穿透)选择器 ::v-deep/deep/及 > > >
- Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance o
- 【Camera专题】手把手撸一份驱动 到 点亮Camera
- 502 (bad gateway) causes and Solutions
- Wechat applet Development Tool Post net:: Err Proxy Connexion Problèmes d'agent défectueux
- Analyzing several common string library functions in C language
- 小程序开发黑马购物商城中遇到的问题
猜你喜欢
![[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

詳細些介紹如何通過MQTT協議和華為雲物聯網進行通信

Performance test | script template sorting, tool sorting and result analysis

Solution for processing overtime orders (Overtime unpaid)
![[fluent] hero animation (hero animation use process | create hero animation core components | create source page | create destination page | page Jump)](/img/68/65b8c0530cfdc92ba4f583b0162544.gif)
[fluent] hero animation (hero animation use process | create hero animation core components | create source page | create destination page | page Jump)

ByteDance data Lake integration practice based on Hudi

使用Go语言实现try{}catch{}finally

Depth (penetration) selector:: v-deep/deep/ and > > >
![[shutter] bottom navigation bar implementation (bottomnavigationbar bottom navigation bar | bottomnavigationbaritem navigation bar entry | pageview)](/img/41/2413af283e8f1db5d20ea845527175.gif)
[shutter] bottom navigation bar implementation (bottomnavigationbar bottom navigation bar | bottomnavigationbaritem navigation bar entry | pageview)

Learn BeanShell before you dare to say you know JMeter
随机推荐
Explore the conversion between PX pixels and Pt pounds, mm and MM
【Camera专题】HAL层-addChannel和startChannel简析
Huakaiyun (Zhiyin) | virtual host: what is a virtual host
Cancellation of collaboration in kotlin, side effects of cancellation and overtime tasks
Machine learning notes (constantly updating...)
Groovy, "try with resources" construction alternative
stm32F407-------ADC
缺少库while loading shared libraries: libisl.so.15: cannot open shared object file: No such file
Wechat applet Development Tool Post net:: Err Proxy Connexion Problèmes d'agent défectueux
Certaines fonctionnalités du développement d'applets
How do it students find short-term internships? Which is better, short-term internship or long-term internship?
leetcode961. Find the elements repeated N times in the array with length 2n
In 2022, 95% of the three most common misunderstandings in software testing were recruited. Are you that 5%?
MySQL learning 03
Prohibited package name
【CodeForces】CF1338A - Powered Addition【二进制】
【Camera专题】Camera dtsi 完全解析
返回一个树形结构数据
stm32F407-------IIC通讯协议
What are MySQL locks and classifications