比赛 数列操作练习题 评测结果 TTTTTTTTT
题目名称 数列操作B 最终得分 0
用户昵称 rvalue 运行时间 9.000 s
代码语言 C++ 内存使用 1.05 MiB
提交时间 2017-03-18 19:48:33
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int INF=0x7FFFFFFF;
const int MAXN=100010;

int n;
int m;
int a[MAXN];
int c[MAXN];

void Initialize();
int Query(int);
void Add(int,int);
void Build();
int LowBit(int);
void FastRead(int&);
void FastRead(long long &);

int Main(){
	char buf[10];
	int from;
	int to;
	int add;

	Initialize();
	FastRead(m);
	for(int i=0;i<m;i++){
		scanf("%s",buf);
		switch(buf[0]){
			case 'A':
				FastRead(from);
				FastRead(to);
				FastRead(add);
				Add(from,add);
				Add(to+1,-add);
			break;
			case 'Q':
				FastRead(from);
				// printf("x->%d\n",Query(from));
				printf("%d\n",a[from]+Query(from));
			break;
		}
	}
	return 0;
}

void FastRead(int& target){
	target=0;
	register char ch=getchar();
	while(ch>'9'||ch<'0')
		ch=getchar();
	while(ch<='9'&&ch>='0'){
		target=target*10+ch-48;
		ch=getchar();
	}
}

void FastRead(long long& target){
	target=0;
	register char ch=getchar();
	while(ch>'9'||ch<'0')
		ch=getchar();
	while(ch<='9'&&ch>='0'){
		target=target*10+ch-48;
		ch=getchar();
	}
}

void Initialize(){
#ifndef ASC_LOCAL
	freopen("shulie.in","r",stdin);
	freopen("shulie.out","w",stdout);
#endif
	int tmp;
	FastRead(n);
	for(int i=1;i<=n;i++){
		FastRead(a[i]);
	}
}

int Query(int x){
	int ans=0;
	for(int i=x;i>0;i-=LowBit(i))
		ans+=c[i];
	return ans;
}

void Add(int x,int add){
	for(int i=x;i<=n;i+=LowBit(i))
		c[i]+=add;
}

inline int LowBit(int x){
	return x&-x;
}

int WORKING=Main();
int main(){;}