当前位置:网站首页>【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;
}
边栏推荐
- 技术大佬准备就绪,话题C位由你决定
- Redis: simple use of redis
- stm32F407-------ADC
- 苏世民:25条工作和生活原则
- What are the differences between software testers with a monthly salary of 7K and 25K? Leaders look up to you when they master it
- 我的创作纪念日
- Network security - dynamic routing protocol rip
- Leetcode 183 Customers who never order (2022.07.02)
- Comment communiquer avec Huawei Cloud IOT via le Protocole mqtt
- Anna: Beibei, can you draw?
猜你喜欢

Solution for processing overtime orders (Overtime unpaid)

Ni visa fails after LabVIEW installs the third-party visa software

LabVIEW安装第三方VISA软件后NI VISA失效

Detailed introduction to the usage of Nacos configuration center

Learn BeanShell before you dare to say you know JMeter

小程序開發的部分功能

微信小程序开发工具 POST net::ERR_PROXY_CONNECTION_FAILED 代理问题

Processing of tree structure data

Redis:Redis的简单使用
![[shutter] shutter debugging (debugging control related functions | breakpoint management | code operation control)](/img/fe/c053f8d116eb307733177283a26318.png)
[shutter] shutter debugging (debugging control related functions | breakpoint management | code operation control)
随机推荐
Explore the conversion between PX pixels and Pt pounds, mm and MM
Basic operation of view
es6 filter() 数组过滤方法总结
2022 financial product revenue ranking
Startup mode and scope builder of collaboration in kotlin
Network security - talking about security threats
小程序开发黑马购物商城中遇到的问题
Network security - scan
easyExcel
Asian Games countdown! AI target detection helps host the Asian Games!
Modify table structure
Iptables layer 4 forwarding
File class (check)
Network security - virus
leetcode961. Find the elements repeated N times in the array with length 2n
stm32F407-------ADC
Distributed transaction solution
In 2022, 95% of the three most common misunderstandings in software testing were recruited. Are you that 5%?
MySQL learning 03
PyTorch 卷积网络正则化 DropBlock