Beispiel #1
0
int main(int argc, const char * argv[]) {
    int ff;
    int v1, v2, t;
    char query[20];
    BIT bit;
    scanf("%d", &ff);
    for (int tt = 1; tt <= ff; tt++) {
        printf("Case %d:\n", tt);
        int n;
        scanf("%d", &n);
        bit.build(n+1);
        for (int i = 1; i <= n; i++) {
            scanf("%d", &t);
            bit.modify(i, t);
        }
        bool fl = true;
        while (fl) {
            scanf("%s", query);
            switch (query[0]) {
                case 'Q':
                    scanf("%d %d", &v1, &v2);
                    printf("%d\n", bit.sum(v1, v2));
                    break;
                case 'A':
                    scanf("%d %d", &v1, &v2);
                    bit.modify(v1, v2);
                    break;
                case 'S':
                    scanf("%d %d", &v1, &v2);
                    bit.modify(v1, -v2);
                    break;
                case 'E':
                    fl = false;
                    break;
            }
        }
    }
}
int main() {
	int C = 0, T, q, x, y;
	scanf("%d", &T);
	while (++C <= T) {
		bit.init();
		scanf("%d", &n);
		for (int i = 1; i <= n; i++) {
			scanf("%d", &x);
			bit.modify(i, x);
		}
		scanf("%d", &q);
		while (q--) {
			scanf("%d %d", &x, &y);
			printf("%d\n", bit.query(x, y));
		}
	}
}