#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,x,x1,y,z;
int a[100010],d[100010],c[100010];
int lowbit(int num){return num&-num;}
void add(int x,int y){
int a=x;
while(x<=n) d[x]+=y,c[x]+=(a-1)*y,x+=lowbit(x);
return;
}
int get(int x){
int ans=0,ans1=0,a=x;
while(x) ans+=d[x],ans1+=c[x],x-=lowbit(x);
return ans*a-ans1;
}
signed main(){
cin>>n>>m;
for(int i=1;i<=n;++i) scanf("%ld",&a[i]),add(i,a[i]-a[i-1]);
for(int i=1;i<=m;++i){
scanf("%ld",&x);
if(x==1){
scanf("%ld%ld%ld",&x1,&y,&z);
add(x1,z);
add(y+1,-z);
}else{
scanf("%ld%ld",&y,&z);
cout<<get(z)-get(y-1)<<endl;
}
}
return 0;
}
标签:&&,树状,int,long,num,100010,区间
From: https://www.cnblogs.com/wenzhihao2023/p/17989791