# [HDU-1166] ```cpp= #include <iostream> using namespace std; #define N int(5*1e4) int t, n, Case, a, b; int total[N<<2]; char c[7]; void pull(int x){ total[x] = total[x<<1] + total[x<<1|1]; } void build(int x, int l, int r){ if (l == r){ cin >> total[x]; return; } int mid = (l+r) / 2; build(x<<1, l, mid); build(x<<1|1, mid+1, r); pull(x); } int query(int x, int l, int r, int ql, int qr){ if (ql <= l && qr >= r){ return total[x]; } int ret = 0; int mid = (l+r) / 2; if (ql <= mid){ ret += query(x<<1, l, mid, ql, qr); } if (qr > mid){ ret += query(x<<1|1, mid+1, r, ql, qr); } return ret; } void update(int x, int l, int r, int pos, int val){ if (l == r){ total[x] += val; return; } int mid = (l+r) / 2; if (pos <= mid) update(x<<1, l, mid, pos, val); else update(x<<1|1, mid+1, r, pos, val); pull(x); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> t; while (t--){ cin >> n; Case++; cout << "Case " << Case << ":\n"; build(1, 1, n); while(cin >> c){ if (c[0] == 'E') break; else if (c[0] == 'Q'){ cin >> a >> b; cout << query(1, 1, n, a, b) << "\n"; } else if (c[0] == 'A'){ cin >> a >> b; update(1, 1, n, a, b); } else if (c[0] == 'S'){ cin >> a >> b; update(1, 1, n, a, -b); } } } } ```