lwthree @ 2024-10-13 00:25:40
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000
int a[MAXN+50],d[MAXN*4+50],b[MAXN*4+50];
int n;
void build(int s,int t,int p){
if (s==t) {d[p]==a[s];return;}
int m=(s+t)>>1;
build(s,m,p*2),build(m+1,t,p*2+1);
d[p]=d[p*2]+d[p*2+1];
}
int getsum(int l,int r,int s,int t,int p){
if (l<=s&&r>=t) return d[p];
int sum=0,m=(s+t)>>1;
if (b[p]){
d[p*2]+=b[p]*(m-s+1),d[p*2+1]+=b[p]*(t-m);
b[p*2]+=b[p],b[p*2+1]+=b[p];
b[p]=0;
}
if (l<=m) sum+=getsum(l,r,s,m,p*2);
if (r>t) sum+=getsum(l,r,m+1,t,p*2+1);
return sum;
}
void update(int l,int r,int s,int t,int c,int p){
if (l<=s&&r>=t){
d[p]+=c*(t-s+1),b[p]+=c;return;
}
int m=(s+t)>>1;
if (b[p]&&s!=t){
d[p*2]+=b[p]*(m-s+1),d[p*2+1]+=b[p]*(t-m);
b[p*2]+=b[p],b[p*2+1]+=b[p];
b[p]=0;
}
if (l<=m) update(l,r,s,m,c,p*2);
if (r>m) update(l,r,m+1,t,c,p*2+1);
d[p]=d[p*2]+d[p*2+1];
}
int main(){
int T;
cin>>n>>T;
for (int i=1;i<=n;i++) cin>>a[i];
build(1,n,1);
while (T--){
int i,x,y,k;
cin>>i;
if (i==1){
cin>>x>>y>>k;
update(1,n,x,y,k,1);
}
else{
cin>>x>>y;
cout<<getsum(1,n,x,y,1)<<endl;
}
}
return 0;
}
by lwthree @ 2024-10-13 00:33:12
由于
if (s==t) {d[p]==a[s];return;}
引发的惨案
by lwthree @ 2024-10-13 00:35:20
靠,还是不行
by lwthree @ 2024-10-13 00:45:18
现在70pts
by cff_0102 @ 2024-10-13 01:03:32
@lwthree 注意到你使用了 int