#include <bits/stdc++.h> using namespace std; const int maxn = 5e4+10; #define ls (rt<<1) #define rs (rt<<1|1) #define mid (l+r)/2 int a[maxn]; int n; struct Node{ int sum; }node[maxn<<2]; void push_up(int rt){ node[rt].sum = node[ls].sum+node[rs].sum; } void build(int rt, int l, int r){ node[rt].sum = 0; if(l == r){ node[rt].sum = a[l]; return ; } build(ls, l, mid); build(rs, mid+1, r); push_up(rt); } void update(int rt, int l, int r, int pos, int val){ if(l>r) return; if(l == pos && r == pos){ node[rt].sum += val; return; } if(pos<=mid){ update(ls, l, mid, pos, val); push_up(rt); } else if(pos>mid){ update(rs, mid+1, r, pos, val); push_up(rt); } return; } int query(int rt, int l, int r, int ql, int qr){ if(l>r) return 0; if(l == ql&&r == qr){ return node[rt].sum; } if(qr<=mid){ return query(ls, l, mid, ql, qr); } else if(ql>mid){ return query(rs, mid+1, r, ql, qr); } else{ return query(ls, l, mid, ql, mid)+ query(rs, mid+1, r, mid+1, qr); } } int main(){ ios::sync_with_stdio(false); int t; cin>>t; int kase = 1; while(t--){ cin>>n; for(int i=1; i<=n; i++){ cin>>a[i]; } build(1, 1, n); cout<<"Case "<<kase++<<":"<<endl; string op; int u, v; while(cin>>op){ if(op[0] == 'E') break; cin>>u>>v; if(op[0] == 'A'){ update(1, 1, n, u, v); }else if(op[0] == 'S'){ update(1, 1, n, u, -v); } else{ cout<<query(1, 1, n, u, v)<<endl; } } } return 0; }
|