ABC388
好像已经很久没有写过题解了
C
link
对于每一个糕点,二分查找大于等于它大小的二倍的糕点的位置(可以用
猜猜我是啥
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
int a[500005];
int ans;
signed main(){
cin >> n;
for(int i = 1;i <= n;++ i)
cin >> a[i];
for(int i = 1;i <= n;++ i){
int w = a[i]*2;
int wz = lower_bound(a+1,a+1+n,w)-a;
ans += n-wz+1;
}
cout << ans;
return 0;
}
D
link
设
首先我们可以得出,石头只会从前往后送;而且我们还可以得出,
我们知道,区间加一可以用差分,可是差分要全做完之后做前缀和才能知道结果,怎么办呢?我们知道如果一个数成年了就不会再得到石头了,也就是说当我们需要知道
猜猜我是啥
#include<bits/stdc++.h>
using namespace std;
int n;
int a[500005];
int cf[500005];
signed main(){
cin >> n;
for(int i = 1;i <= n;++ i)
cin >> a[i],cf[i] = a[i]-a[i-1];
for(int i = 1;i <= n;++ i){
a[i] = cf[i-1]+cf[i];
cf[i] += cf[i-1];
int w = min(a[i],n-i);
cf[i+1]++;
cf[i+w+1]--;
a[i] -= w;
}
for(int i = 1;i <= n;++ i)
cout << a[i] << " ";
return 0;
}
E
link
二分答案,对于一个答案
猜猜我是啥
#include<bits/stdc++.h>
using namespace std;
int n;
int a[500005];
bool check(int x){
for(int i = 1,j = n-x+1;i <= x;++ i,++ j){
if(a[i]*2 > a[j]) return false;
}
return true;
}
signed main(){
cin >> n;
for(int i = 1;i <= n;++ i)
cin >> a[i];
int l = 0,r = n/2;
while(l < r){
int mid = (l+r+1)/2;
if(check(mid)) l = mid;
else r = mid-1;
}
cout << l;
return 0;
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战