#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<string.h> using namespace std; #define BITMAX 50001 //数组大小 typedef int valueType; //元素类型定义 valueType BITree[BITMAX]; //一维树状数组,初始化 /* 2^k k表示节点编号 x 二进制末尾 0 的个数 */ inline int lowbit(int x) { return x & (-x); } /* 一维,C[x]=A[ x-lowbit(x)+1 ....... x ] */ /* 节点 x 的值增加 add */ /* x 不能为 0 ,,应该从 1 起步,否则无限循环下去 */ inline void addPoint(int x, int add, int n) { for (int i = x; i <= n; i += lowbit(i)){ BITree[i] += add; } } /* 获取前 x 项和*/ inline valueType readSum(int x) { valueType sum = 0; for (int i = x; i > 0; i -= lowbit(i)) sum += BITree[i]; return sum; } int main() { int t, n; char s[6]; int a, b; scanf("%d", &t); for (int w = 1; w <= t; ++w){ printf("Case %d: ", w); scanf("%d", &n); memset(BITree, 0, sizeof(BITree)); for (int i = 1; i <= n; ++i){ scanf("%d", &a); addPoint(i, a, n); } while (scanf("%s",s) && s[0] != 'E'){ switch (s[0]) { case 'A': scanf("%d %d", &a, &b); addPoint(a, b, n); break; case 'S': scanf("%d %d", &a, &b); addPoint(a, -b, n); break; case 'Q': scanf("%d %d", &a, &b); printf("%d ", (readSum(b) - readSum(a - 1))); break; default: break; } } } }