当前位置:网站首页>【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;
}
边栏推荐
- stm32F407-------ADC
- Network security - the simplest virus
- Internal connection query and external connection
- File class (check)
- y54.第三章 Kubernetes从入门到精通 -- ingress(二七)
- Cfdiv2 fixed point guessing- (interval answer two points)
- Detailed introduction to the usage of Nacos configuration center
- [shutter] shutter debugging (debugging fallback function | debug method of viewing variables in debugging | console information)
- Startup mode and scope builder of collaboration in kotlin
- Summary of ES6 filter() array filtering methods
猜你喜欢
![[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)

技术大佬准备就绪,话题C位由你决定
![[fluent] fluent debugging (debug debugging window | viewing mobile phone log information | setting normal breakpoints | setting expression breakpoints)](/img/ac/bf83f319ea787c5abd7ac3fabc9ede.jpg)
[fluent] fluent debugging (debug debugging window | viewing mobile phone log information | setting normal breakpoints | setting expression breakpoints)

Bottleneck period must see: how can testers who have worked for 3-5 years avoid detours and break through smoothly

详细些介绍如何通过MQTT协议和华为云物联网进行通信

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

What are the key points often asked in the redis interview

Depth (penetration) selector:: v-deep/deep/ and > > >

微信小程序開發工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理問題

Button button adaptive size of wechat applet
随机推荐
8 free, HD, copyright free video material download websites are recommended
How to find summer technical internship in junior year? Are you looking for a large company or a small company for technical internship?
stm32F407-------IIC通讯协议
Distributed transaction solution
浏览器是如何对页面进行渲染的呢?
技术大佬准备就绪,话题C位由你决定
去除网页滚动条方法以及内外边距
Introduce in detail how to communicate with Huawei cloud IOT through mqtt protocol
【Camera专题】手把手撸一份驱动 到 点亮Camera
A 30-year-old software tester, who has been unemployed for 4 months, is confused and doesn't know what to do?
Network security ACL access control list
详细些介绍如何通过MQTT协议和华为云物联网进行通信
Kotlin middle process understanding and Practice (II)
DML Foundation
自定义组件、使用npm包、全局数据共享、分包
What are MySQL locks and classifications
Redis: simple use of redis
Leetcode(540)——有序数组中的单一元素
Leetcode 183 Customers who never order (2022.07.02)
Return the only different value (de duplication)