//线段树
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define MAX 50000
struct Node{
int num, l, r;
}c[MAX * 3];
void Create(int rt, int l, int r)
{
c[rt].l = l;
c[rt].r = r;
if(r == l)
{
scanf("%d", &c[rt].num);
return ;
}
int mid = (l + r) >> 1;
Create(rt << 1, l, mid);
Create(rt << 1 | 1, mid + 1, r);
c[rt].num = c[rt << 1].num + c[rt << 1 | 1].num;
}
void Update(int rt, int l, int r, int v)
{
if(l <= c[rt].l && c[rt].r <= r)
{
c[rt].num += v;
return ;
}
int mid = (c[rt].l + c[rt].r) >> 1;
if(l <= mid)
Update(rt << 1, l, r, v);
if(mid < r)
Update(rt << 1 | 1, l, r, v);
c[rt].num = c[rt << 1].num + c[rt << 1 | 1].num;
}
int Query(int rt, int l, int r)
{
if(l <= c[rt].l && c[rt].r <= r)
{
return c[rt].num;
}
int mid = (c[rt].l + c[rt].r) >> 1;
int le = 0, re = 0;
if(l <= mid)
le = Query(rt << 1, l, r);
if(mid < r)
re = Query(rt << 1 | 1, l, r);
return le + re;
}
int main()
{
int t, n;
int x, y;
char str[20];
scanf("%d", &t);
for(int k = 1; k <= t; k++)
{
scanf("%d", &n);
Create(1, 1, n);
printf("Case %d:\n", k);
while(scanf("%s", str) && str[0] != 'E')
{
scanf("%d %d", &x, &y);
if(str[0] == 'A') Update(1, x, x, y);
else if(str[0] == 'S') Update(1, x, x, -y);
else printf("%d\n", Query(1, x, y));
}
}
return 0;
}
//树状数组
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
#define MAX 50000
int n;
int c[MAX + 10];
int lowbit(int x)
{
return x & -x;
}
void Update(int x, int val)
{
while(x <= n)
{
c[x] += val;
x += lowbit(x);
}
}
int get_sum(int x)
{
int re = 0;
while(x > 0)
{
re += c[x];
x -= lowbit(x);
}
return re;
}
int main()
{
int t, val;
int x, y;
char str[20];
scanf("%d", &t);
for(int k = 1; k <= t; k++)
{
scanf("%d", &n);
memset(c, 0, sizeof(c));
for(int i = 1; i <= n; i++)
{
scanf("%d", &val);
Update(i, val);
}
printf("Case %d:\n", k);
while(scanf("%s", str) && str[0] != 'E')
{
scanf("%d %d", &x, &y);
if(str[0] == 'A') Update(x, y);
else if(str[0] == 'S') Update(x, -y);
else printf("%d\n", get_sum(y) - get_sum(x-1));
}
}
return 0;
}
//zkw线段树
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
#define MAX 50000
int c[MAX * 3];
int M;
void Create(int n)
{
for(M = 1; M <= n + 1; M <<= 1);
for(int i = M + 1; i <= M + n; i++) scanf("%d", &c[i]);
for(int i = M - 1; i > 0; i--) c[i] = c[i << 1] + c[i << 1 | 1];
}
void Update(int n, int v)
{
for(c[n += M] += v, n >>= 1; n > 0; n >>= 1) c[n] = c[n << 1] + c[n << 1 | 1];
}
int Query(int s, int t)
{
int sum = 0;
for(s = s + M - 1, t = t + M + 1; s ^ t ^ 1; s >>= 1, t >>= 1) // s ^ t ^ 1 => s = t - 1
{
if(~s & 1) //是否为左节点
sum += c[s ^ 1]; // 取右节点
if(t & 1) //是否为右节点
sum += c[t ^ 1]; // 取左节点
}
return sum;
}
int main()
{
int t, n;
int x, y;
char str[20];
scanf("%d", &t);
for(int k = 1; k <= t; k++)
{
scanf("%d", &n);
Create(n);
printf("Case %d:\n", k);
while(scanf("%s", str) && str[0] != 'E')
{
scanf("%d %d", &x, &y);
if(str[0] == 'A') Update(x, y);
else if(str[0] == 'S') Update(x, -y);
else printf("%d\n", Query(x, y));
}
}
return 0;
}