树状数组。对点更新,区间求和。用线段树会比较省心。而树状数组的数组中保存的并不都是单点的值,不能直接赋值(至少我现在不会。。。)。所以只要解决如何更新点的值,剩下的就是默写模板了。在开一个数组来记录每个点的值,每次更新时,用新旧两个差值来更新树状数组,要记得记录点的新值。区间求和时注意左端点是开的,右端点是闭的。
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<string>
#include<queue>
#include<cmath>
///LOOP
#define REP(i, n) for(int i = 0; i < n; i++)
#define FF(i, a, b) for(int i = a; i < b; i++)
#define FFF(i, a, b) for(int i = a; i <= b; i++)
#define FD(i, a, b) for(int i = a - 1; i >= b; i--)
#define FDD(i, a, b) for(int i = a; i >= b; i--)
///INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)
#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)
#define RFI(n) scanf("%lf", &n)
#define RFII(n, m) scanf("%lf%lf", &n, &m)
#define RFIII(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)
#define RFIV(n, m, k, p) scanf("%lf%lf%lf%lf", &n, &m, &k, &p)
#define RS(s) scanf("%s", s)
///OUTPUT
#define PN printf("\n")
#define PI(n) printf("%d\n", n)
#define PIS(n) printf("%d ", n)
#define PS(s) printf("%s\n", s)
#define PSS(s) printf("%s ", n)
///OTHER
#define PB(x) push_back(x)
#define CLR(a, b) memset(a, b, sizeof(a))
#define CPY(a, b) memcpy(a, b, sizeof(b))
#define display(A, n, m) {REP(i, n){REP(j, m)PIS(A[i][j]);PN;}}
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int MOD = 100000000;
const int INFI = 1e9 * 2;
const LL LINFI = 1e17;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int N = 222222;
const int M = 1111;
const int move[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1};
int c[N], a[N];
void add(int x, int v)
{
while(x < N)
{
c[x] += v;
x += x & (-x);
}
}
int sum(int x)
{
int s = 0;
while(x)
{
s += c[x];
x -= x & (-x);
}
return s;
}
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n, x, y, cas = 1;
char op[11];
while(RI(n), n)
{
if(cas > 1)puts("");
printf("Case %d:\n", cas++);
CLR(c, 0);
FFF(i, 1, n)
{
RI(a[i]);
add(i, a[i]);
}
while(RS(op), op[0] != 'E')
{
RII(x, y);
if(op[0] == 'S')
{
add(x, y - a[x]);
a[x] = y;
}
else PI(sum(y) - sum(x - 1));
}
}
return 0;
}