内存最优
2026-07-27 15:35:24
发布于:河南
1阅读
0回复
0点赞
击败了100.00的人 3.25MB
#include<cstdio>
const int N=5e5+1;
typedef int ll;
ll c[N];
int n,m,op,x,y,k;
inline int lowbit(ll x){return x&-x;}
inline void update(ll x,ll v){while(x<=n)c[x]+=v,x+=lowbit(x);}
inline ll sum(ll x){
ll ans=0;
while(x>0)ans+=c[x],x-=lowbit(x);
return ans;
}
int main(){
scanf("%d%d",&n,&m);
ll last=0,now;
for(int i=1;i<=n;i++){
scanf("%d",&now);
update(i,now-last); // 直接计算差分
last=now;
}
while(m--){
scanf("%d",&op);
if(op==1){
scanf("%d%d%d",&x,&y,&k);
update(x,k);
update(y+1,-k);
}else{
scanf("%d",&x);
printf("%d\n",sum(x));
}
}
return 0;
}
这里空空如也





有帮助,赞一个