样例过了,只有20分。
#include<bits/stdc++.h>
using namespace std;
long long n,m,a[200001],q,p,CIN_JG[200001],z,k,IF;
struct segtree_noet{
long long ved;
long long lazy;
}segtree[100001*4];
void pushdow(int rt,int ln,int rn){
if(segtree[rt].lazy){
segtree[rt*2].lazy=segtree[rt].lazy;
segtree[rt*2+1].lazy=segtree[rt].lazy;
segtree[rt*2].ved+=segtree[rt].lazy*ln;
segtree[rt*2+1].ved+=segtree[rt].lazy*rn;
segtree[rt].lazy=0;
}
return;
}
void gz(int l,int r,int rt){
segtree[rt].lazy=0;
if(l==r){
segtree[rt].ved+=CIN_JG[l];
return;
}
int m=(l+r)/2;
gz(l,m,rt*2);
gz(m+1,r,rt*2+1);
segtree[rt].ved=segtree[rt*2].ved+segtree[rt*2+1].ved;
}
void gx(int L,int R,int c,int l,int r,int rt){
if(L>r||R<l) return ;
if(r<=R&&L<=l){
segtree[rt].ved+=c*(r-l+1);
segtree[rt].lazy+=c;
return;
}
int m=(l+r)/2;
pushdow(rt,m-l+1,r-m);
gx(L,R,c,l,m,rt*2);
gx(L,R,c,m+1,r,rt*2+1);
segtree[rt].ved=segtree[rt*2].ved+segtree[rt*2+1].ved;
}
int dow(int L,int R,int l,int r,int rt){
if(r<=R&&L<=l) return segtree[rt].ved;
if(L>r||R<l) return 0;
int m=(l+r)/2;
pushdow(rt,m-l+1,r-m);
return dow(L,R,l,m,rt*2)+dow(L,R,m+1,r,rt*2+1);
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>CIN_JG[i];
}
gz(1,n,1);
for(int i=1;i<=m;i++){
cin>>IF;
if(IF==1){
cin>>q>>p>>k;
gx(q,p,k,1,n,1);
}else{
cin>>q>>p;
cout<<dow(q,p,1,n,1)<<"\n";
}
}
return 0;
}
救救小蒟蒻吧!