#include<bits/stdc++.h>
using namespace std;
int a[100050];
struct Tree{
int l,r;
long long v,lazy;
}tree[400050];
void build(int l,int r,int p){
tree[p].l=l;
tree[p].r=r;
if(l==r){
tree[p].v=a[l];
return ;
}
build((r+l)/2,l,p*2);
build(r,(r+l)/2+1,p*2);
tree[p].v=tree[p*2].v+tree[p*2+1].v;
return ;
}
void down(int p){
tree[p*2].lazy+=tree[p].lazy;
tree[p*2+1].lazy+=tree[p].lazy;
tree[p*2].v+=(tree[p*2].r-tree[p*2+1].l+1)*tree[p].lazy;
tree[p*2+1].v+=(tree[p*2+1].r-tree[p*2+1].l+1)*tree[p].lazy;
return ;
}
void add(int p,int l,int r,int x){
if(tree[p].l>r||tree[p].r<l) return ;
if(tree[p].l>=l&&tree[p].r<=r){
tree[p].lazy+=x;
tree[p].v+=(tree[p].r-tree[p].l+1)*x;
return ;
}
if(tree[p].lazy) down(p);
add(p*2,l,r,x);
add(p*2+1,l,r,x);
tree[p].v=tree[p*2+1].v+tree[p*2].v;
return ;
}
long long count(int p,int l,int r){
if(tree[p].l>r||tree[p].r<l) return 0;
if(tree[p].l>=l&&tree[p].r<=r) return tree[p].v;
if(tree[p].lazy>0) down(p);
return count(p*2,l,r)+count(p*2+1,l,r);
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
build(1,1,1);
for(int i=1;i<=m;i++){
int q;
scanf("%d",&q);
if(q==1){
int b,c,d;
scanf("%d%d%d",&b,&c,&d);
add(1,b,c,d);
}
if(q==2){
int b,c;
scanf("%d%d%d",&b,&c);
printf("%lld\n",count(1,b,c));
}
}
return 0;
}
不知道为什么会在编译器上出错,求条回关