problem
solution
codes
#include<iostream>
using namespace std;
const int maxn = 100010;
#define lch p<<1
#define rch p<<1|1
struct node{
int val, addmark;
}sgt[maxn<<2];
void pushdown(int p, int l, int r){
if(!sgt[p].addmark)return;
int t = sgt[p].addmark, m=l+r>>1;
sgt[lch].addmark += t;
sgt[rch].addmark += t;
sgt[lch].val += t*(m-l+1);
sgt[rch].val += t*(r-m);
sgt[p].addmark = 0;
}
void update(int p, int l, int r, int ql, int qr, int v){
if(l>qr || r<ql)return ;
if(ql<=l && r<=qr){
sgt[p].val += v*(r-l+1);
sgt[p].addmark += v;
return ;
}
int m = l+r>>1;
if(ql<=m)update(lch,l,m,ql,qr,v);
if(qr>m)update(rch,m+1,r,ql,qr,v);
sgt[p].val = sgt[lch].val+sgt[rch].val;
}
int query(int p, int l, int r, int ql, int qr){
if(ql<=l && r<=qr)return sgt[p].val;
pushdown(p,l,r);
int m = l+r>>1, ans = 0;
if(ql<=m)ans += query(lch,l,m,ql,qr);
if(qr>m)ans += query(rch,m+1,r,ql,qr);
return ans;
}
int main(){
int n, m;
cin>>n;
for(int i = 1; i <= n; i++){
int x; cin>>x; update(1,1,n,i,i,x);
}
cin>>m;
for(int i = 1; i <= m; i++){
int op, x, y, k;
cin>>op;
if(op == 1){
cin>>x>>y>>k;
update(1,1,n,x,y,k);
}else{
cin>>x;
cout<<query(1,1,n,x,x)<<"\n";
}
}
return 0;
}