zzjccc @ 2024-09-17 20:28:00
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int tr[N];
int lazy[N];
int a[N];
void bui(int id,int l,int r){
if(l==r){
tr[id]=a[l];
return;
}
int mid=(l+r)/2;
bui(id*2,l,mid);
bui(id*2+1,mid+1,r);
tr[id]=tr[id*2]+tr[id*2+1];
}
void push_up(int id){
tr[id]=tr[id*2]+tr[id*2+1];
}
void push_down(int id,int l,int r){
if(lazy[id]){
int mid=(l+r)/2;
lazy[id*2]+=lazy[id];
lazy[id*2+1]+=lazy[id];
tr[id*2]+=lazy[id]*(mid-l+1);
tr[id*2+1]+=lazy[id]*(r-mid);
lazy[id]=0;
}
}
void qjgx(int id,int l,int r,int x,int y,int v){
if(x<=l&&y>=r){
lazy[id]+=v;
tr[id]+=v*(r-l+1);
return;
}
push_down(id,l,r);
int mid=(l+r)/2;
if(x<=mid){
qjgx(id*2,l,mid,x,y,v);
}
if(y>mid){
qjgx(id*2+1,mid+1,r,x,y,v);
}
push_up(id);
}
int find(int id,int l,int r,int x,int y){
if(x<=l&&y>=r){
return tr[id];
}
push_down(id,l,r);
int mid=(l+r)/2;
long long ans=0;
if(x<=mid){
ans+=find(id*2,l,mid,x,y);
}
if(y>mid){
ans+=find(id*2+1,mid+1,r,x,y);
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int n,m,op,x,y,k;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
bui(1,1,n);
for(int i=1;i<=m;i++){
cin>>op>>x>>y;
if(op==1){
cin>>k;
qjgx(1,1,n,x,y,k);
}
else if(op==2){
cout<<find(1,1,n,x,y)<<endl;
}
}
return 0;
}
by lhz2022 @ 2024-09-17 20:36:26
因为要开4倍空间
球馆
by kkkcs @ 2024-09-17 20:58:16
@lhz2022 牛币 馆乐
by zzjccc @ 2024-09-18 15:50:42
我修改成了4e5+5,怎么后面三个测试点WA了
by littlep001 @ 2024-10-06 20:29:34
@zzjccc 因为你没开long long