记录编号 367129 评测结果 AAAAAAAAAA
题目名称 1317.数列操作C 最终得分 100
用户昵称 Go灬Fire 是否通过 通过
代码语言 C++ 运行时间 0.166 s
提交时间 2017-01-28 16:43:46 内存使用 3.75 MiB
显示代码纯文本
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
const LL maxn=150000;
LL c[maxn],cc[maxn],sum[maxn];
LL n,m;
LL Lowbit(LL x){
	return x&-x;
} 
LL Query(LL *arr,LL x){
	LL res=0;
	for(LL i=x;i;i-=Lowbit(i))res+=arr[i];
	return res;
}
void Add(LL *arr,LL x,LL add){
	for(LL i=x;i<=n;i+=Lowbit(i))arr[i]+=add;
}
void Init();
int main(){
	freopen("shuliec.in","r",stdin);freopen("shuliec.out","w",stdout);
	Init();
	getchar();getchar();
	return 0;
}
void Init(){
	scanf("%lld",&n);
	for(LL i=1;i<=n;i++){
		scanf("%lld",&sum[i]);
		sum[i]+=sum[i-1];
	}
	scanf("%lld",&m);
	for(LL i=1;i<=m;i++){
		char type[6];scanf("%s",type);
		LL x,y,k;
		if(type[0]=='S'){
			scanf("%lld%lld",&x,&y);
			LL sumr=sum[y]+(y+1)*Query(c,y)-Query(cc,y);
			LL suml=sum[x-1]+(x-1+1)*Query(c,x-1)-Query(cc,x-1);
			printf("%lld\n",sumr-suml);
		}
		else{
			scanf("%lld%lld%lld",&x,&y,&k);
			Add(c,x,k);Add(c,y+1,-k);
			Add(cc,x,x*k);Add(cc,y+1,-(y+1)*k);
		}
	}
}