当前位置:网站首页>【CodeForces】CF1338A - Powered Addition【二进制】
【CodeForces】CF1338A - Powered Addition【二进制】
2022-07-03 02:00:00 【是王同学呀】
题意
给出一个长度为 n ( n < = 100000 ) n ( n < = 100000 ) n(n<=100000)的数组,在第 i i i秒时可以任意选出一些数使它们的值增加 2 i − 1 2^{i-1} 2i−1,问如果要使得该数组不递减至少需要多少秒?
思路
遍历数组,维护一个前缀最大值,如果当前 a [ i ] < m a x c u r a[i]<max_{cur} a[i]<maxcur,说明当前 a [ i ] a[i] a[i]需要补齐 m a x c u r − a [ i ] max_{cur}-a[i] maxcur−a[i]大小,然后当前 a [ i ] a[i] a[i]变为 m a x c u r max_{cur} maxcur,最后 m a x ( m a x c u r − a [ i ] ) max(max_{cur}-a[i]) max(maxcur−a[i])的二进制位数就是我们要求的答案。
AC代码
#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;
}
边栏推荐
- Leetcode(540)——有序数组中的单一元素
- His experience in choosing a startup company or a big Internet company may give you some inspiration
- Redis: simple use of redis
- [shutter] shutter debugging (debugging fallback function | debug method of viewing variables in debugging | console information)
- 可視化yolov5格式數據集(labelme json文件)
- Reprint some Qt development experience written by great Xia 6.5
- Leetcode (540) -- a single element in an ordered array
- Visual yolov5 format data set (labelme JSON file)
- Trial setup and use of idea GoLand development tool
- Technology sharing | Frida's powerful ability to realize hook functions
猜你喜欢

Hard core observation 547 large neural network may be beginning to become aware?

Trial setup and use of idea GoLand development tool

stm32F407-------IIC通讯协议

The testing process that software testers should know

PyTorch 卷积网络正则化 DropBlock

Visualisation de l'ensemble de données au format yolov5 (fichier labelme json)
![[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)

Redis: simple use of redis

In the face of difficult SQL requirements, HQL is not afraid

Recommendation letter of "listing situation" -- courage is the most valuable
随机推荐
小程序開發的部分功能
Recommendation letter of "listing situation" -- courage is the most valuable
What are MySQL locks and classifications
缺少库while loading shared libraries: libisl.so.15: cannot open shared object file: No such file
Swift开发学习
疫情当头,作为Leader如何进行团队的管理?| 社区征文
创建+注册 子应用_定义路由,全局路由与子路由
转载收录6.5大侠写的部分Qt开发经验
[camera special topic] Hal layer - brief analysis of addchannel and startchannel
DML Foundation
Solution for processing overtime orders (Overtime unpaid)
【Camera专题】Camera dtsi 完全解析
可视化yolov5格式数据集(labelme json文件)
PS remove watermark details
Bottleneck period must see: how can testers who have worked for 3-5 years avoid detours and break through smoothly
File class (add / delete)
Asian Games countdown! AI target detection helps host the Asian Games!
PyTorch 卷积网络正则化 DropBlock
微信小程序开发工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理问题
Machine learning notes (constantly updating...)