记录编号 393223 评测结果 AAAAAAAAAAAAAAA
题目名称 数列操作A 最终得分 100
用户昵称 GravatarkZime 是否通过 通过
代码语言 C++ 运行时间 0.384 s
提交时间 2017-04-10 11:01:20 内存使用 5.29 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#define MAXN 100233
using namespace std;

inline void File_Read() {
#ifndef MYLAB
    freopen("shulie.in", "r", stdin);
    freopen("shulie.out", "w", stdout);
#else
    freopen("in.txt", "r", stdin);
#endif
}

struct node{
	int l, r, s;
	node(){;}
	node(int l_, int r_, int s_) {
		l = l_;
		r = r_;
		s = s_;
	}
}nd[MAXN << 2];

int n, a[MAXN], q; 

inline int get_num() {
	int k = 0;
	char c = getchar();
	for(; !isdigit(c); c = getchar());
	for(; isdigit(c); c = getchar()) {
		k = k * 10 + c - '0';
	}
	return k;
}

int build(int x, int l, int r) {
	if(l == r) {
        nd[x].l = l;
        nd[x].r = r;
		nd[x].s = a[l];
		return a[l];
	}
	nd[x].l = l;
	nd[x].r = r;
	nd[x].s = build(x << 1, l, (l + r) / 2) + build(x << 1 | 1, (l + r) / 2 + 1, r);
	return nd[x].s;
}

int get_sum(int x, int l, int r) {
    if(nd[x].l == l && nd[x].r == r) {
        return nd[x].s;
    }
    else if(r <= nd[x << 1].r) {
        return get_sum(x << 1, l, r);
    }
    else if(l >= nd[x << 1 | 1].l) {
        return get_sum(x << 1 | 1, l, r);
    }
    else{
        return get_sum(x << 1, l, nd[x << 1].r) + get_sum(x << 1 | 1, nd[x << 1 | 1].l, r);
    }
}

inline void update(int k, int nu) {
    int x = 1;
    while (nd[x].l != nd[x].r) {
        int mid = nd[x].l + nd[x].r;
        mid /= 2;
        if(k <= mid) {
            x = x << 1;
        }
        else {
            x = x << 1 | 1;
        }
    }
    while(x) {
        nd[x].s += nu;
        x /= 2;
    }
}

int main() {
    File_Read();
	n = get_num();
	for(int i = 1; i <= n; i++) {
		a[i] = get_num();
	}
    build(1, 1, n);
/*
    for(in it i = 1 ; i <= n; i++) {
        printf("%d  :  l : %d  r : %d  s : %d\n", i, nd[i].l, nd[i].r, nd[i].s);
    }	
*/
    q = get_num();
    while(q--) {
        char ask[3];
        scanf("%s", ask);
        if(ask[0] == 'S') {
            int le = get_num();
            int ri = get_num();
            printf("%d\n", get_sum(1, le, ri));
        }
        else if(ask[0] == 'A') {
            int k = get_num();
            update(k, get_num());
        }
    }
}