[第1章 1.2t4] 好消息坏消息

97 字
1 分钟
[第1章 1.2t4] 好消息坏消息
//本题深入理解了两项
//1.针对每个窗口要先清整,再推入,最后判断窗口大小
//2.使用sum数组可以解决此类涉及到求和的问题
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n;
cin>>n;
vector<ll> a(2*n+2);
for(ll i=1;i<=n;i++){
cin>>a[i];
a[n+i]=a[i];
}
vector<ll> sum(2*n+2);
sum[0]=0;
for(ll i=1;i<=2*n;i++){
sum[i]=sum[i-1]+a[i];
}
deque<ll> dq;
ll ans=0;
for(ll i=1;i<2*n;i++){
while(!dq.empty()&&sum[dq.back()]>=sum[i])dq.pop_back();
dq.push_back(i);
if(i>=n){
while(!dq.empty()&&i-dq.front()>n)dq.pop_front();
if(sum[dq.front()]-sum[i-n]>=0)ans++;
}
}
cout<<ans<<endl;
return 0;
}

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或打赏支持!

打赏
[第1章 1.2t4] 好消息坏消息
https://hecloud.top/posts/oi/12t4-好消息坏消息/
作者
贺小云
发布于
2026-06-26
许可协议
CC BY-NC-SA 4.0

评论区

Profile Image of the Author
贺小云
热爱技术与折腾的博客 Dancing with uncertainty. 与不确定性共舞
公告
出于成本考虑,贺云已全面转型Serverless架构
分类
标签
碎碎念
站点统计
文章
68
分类
6
标签
38
总字数
46,536
运行时长
0
最后活动
0 天前
站点信息
构建平台
GitHub Actions
博客版本
Firefly v6.16.5
文章许可
CC BY-NC-SA 4.0

当前页面没有目录