/tmp/tmpst7v_6cd/src:65:15: 警告:#undef 指示的末尾有多余的标识符 #undef ll (p<<1) ^ /tmp/tmpst7v_6cd/src:66:15: 警告:#undef 指示的末尾有多余的标识符 #undef lt tree[(p<<1)] ^~~~ /tmp/tmpst7v_6cd/src:67:15: 警告:#undef 指示的末尾有多余的标识符 #undef rr (p<<1|1) ^ /tmp/tmpst7v_6cd/src:68:15: 警告:#undef 指示的末尾有多余的标识符 #undef rt tree[(p<<1)|1] ^~~~ /tmp/tmpst7v_6cd/src:69:14: 警告:#undef 指示的末尾有多余的标识符 #undef t tree[p] ^~~~ /tmp/tmpst7v_6cd/src: 在成员函数‘void ST::build(int, int, int)’中: /tmp/tmpst7v_6cd/src:24:17: 警告:unused variable ‘tmp’ [-Wunused-variable] lll tmp; ^~~
code
#include <iostream>
#include <cstdio>
using namespace std;
#define MaxN 100002
#define lll long long
int N;
/*Segument Tree*/
struct Tree{
int l,r;
lll val,laz;
};
struct ST{
#define ll p<<1
#define lt tree[(p<<1)]
#define rr (p<<1|1)
#define rt tree[(p<<1)|1]
#define t tree[p]
struct Tree tree[MaxN<<2];
void build(int p,int l,int r){
t.l = l,t.r=r;
if(l==r){
lll tmp;
scanf("%lld",&t.val);
return ;
}
int mid = (l+r)>>1;
build(ll,l,mid);
build(rr,mid+1,r);
t.val = lt.val+rt.val;
}
void spr(int p){
if(t.laz){
lt.val += t.laz*(lt.r-lt.l+1);
rt.val += t.laz*(rt.r-rt.l+1);
lt.laz += t.laz;
rt.laz += t.laz;
t.laz = 0;
}
}
void change(int p,int l,int r,int val){
if(t.l>=l&&t.r<=r){
t.val += (lll)val*(t.r-t.l+1);
t.laz += val;
return ;
}
spr(p);
int mid = (t.l+t.r)>>1;
if(l<=mid) change(ll,l,r,val);
if(r> mid) change(rr,l,r,val);
t.val = lt.val + rt.val;
}
lll ask (int p,int l,int r){
if(t.l>=l && t.r <= r){
return t.val;
}
spr(p);
lll ans = 0;
int mid = (t.l+t.r) >> 1;
if(l <= mid) ans += ask(ll,l,r);
if(r > mid) ans += ask(rr,l,r);
return ans;
}
#undef ll (p<<1)
#undef lt tree[(p<<1)]
#undef rr (p<<1|1)
#undef rt tree[(p<<1)|1]
#undef t tree[p]
}seg;
int M;
int main()
{
scanf("%d%d",&N,&M);
seg.build(1,1,N);
int t1,t2,t3;
for(int i = 1;i<=M;i++){
scanf("%d",&t1);
if(t1 == 1){
scanf("%d %d %d",&t1,&t2,&t3);
seg.change(1,t1,t2,t3);
}else {
scanf("%d %d",&t2,&t3);
cout<<seg.ask(1,t2,t3)<<endl;
}
}
return 0;
}