Bluish_Light @ 2024-07-16 07:50:08
Code:
#include<bits/stdc++.h>
using namespace std;
long long n,m,pd,a[100005],tree[400005],x,y,k,ly[400005];
void push(int u){
tree[u]=tree[u*2]+tree[u*2+1];
}
bool allin(int l,int r,int L,int R){
return (L>=l) and (R<=r);
}
bool allout(int l,int r,int L,int R){
return (L>r) or (R<l);
}
void maketag(int u,int len,int k){
ly[u]+=k;
tree[u]+=len*k;
}
void pushdown(int u,int l,int r){
int key=l+r>>1;
maketag(u*2,key-l+1,ly[u]);
maketag(u*2+1,r-key,ly[u]);
ly[u]=0;
}
void build(int u,int l,int r){
if(l==r){
tree[u]==a[l];
return ;
}
int key=l+r>>1;
build(u*2,l,key),build(u*2+1,key+1,r);
push(u);
}
void update(int u,int L,int R,int l,int r,int k){
if(allin(l,r,L,R)) maketag(u,R-L+1,k);
else if(!allout(l,r,L,R)){
int key=L+R>>1;
pushdown(u,L,R);
update(u*2,L,key,l,r,k);
update(u*2+1,key+1,R,l,r,k);
push(u);
}
}
int query(int u,int L,int R,int l,int r){
if(allin(l,r,L,R)) return tree[u];
else if(!allout(l,r,L,R)){
int key=(L+R)/2;
pushdown(u,L,R);
return query(u*2,L,key,l,r)+query(u*2+1,key+1,R,l,r);
}
else return 0;
}
int main(){
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
build(1,1,n);
for(int i=1;i<=m;i++){
cin>>pd;
if(pd==1){
cin>>x>>y>>k;
update(1,1,n,x,y,k);
}
else{
cin>>x>>y;
cout<<query(1,1,n,x,y)<<'\n';
}
}
return 0;
}
0pts全WA,样例也没过,实在不知道错哪了
by wh__ @ 2024-07-16 07:56:55
第25行
tree[u]==a[l];
自己看看
by Bluish_Light @ 2024-07-16 07:58:07
/kk
by Bluish_Light @ 2024-07-16 07:58:40
此贴结