记录编号 101220 评测结果 AAAAAAAAAAAAAAAA
题目名称 数列操作A 最终得分 100
用户昵称 GravatarOI永别 是否通过 通过
代码语言 C++ 运行时间 0.143 s
提交时间 2014-05-10 20:12:22 内存使用 0.70 MiB
显示代码纯文本
#include<cstdio>
#include<iostream>
using namespace std;
#define N 100005
#define lowbit(x) x & (-x)
int c[N];
int n;
inline int getint(){
	int x = 0; char ch;
	while (!isdigit(ch = getchar()));
	x = ch - 48;
	while (isdigit(ch = getchar())) x = x * 10 + ch - 48;
	return x;
}

void insert(int x, int z){
	for (int i = x; i <= n; i += lowbit(i))
		c[i] += z;
}
int ask(int x){
	int ans = 0;
	for (int i = x; i > 0; i -= lowbit(i))
		ans += c[i];
	return ans;
}
int main(){
	freopen("shulie.in", "r", stdin);
	freopen("shulie.out", "w", stdout);
	//scanf("%d",&n);
	n = getint();
	int x, y;
	for (int i = 1; i <= n; i++)
		x = getint(),insert(i,x);
	int Q;
	Q = getint();
	char ch;
	
	for (;Q--;){
		while (1){
			ch = getchar();
			if (ch == 'A' || ch == 'S') break;
		}
		switch(ch){
			case 'A':{
				x = getint(); y = getint();
				insert(x, y);
				break;
			}
			case 'S':{
				x = getint(); y = getint();
				printf("%d\n",ask(y) - ask(x - 1));
				break;
			}
		}
	}
	return 0;
}