记录编号 367137 评测结果 AAAAAAAAAA
题目名称 1317.数列操作C 最终得分 100
用户昵称 Go灬Fire 是否通过 通过
代码语言 C++ 运行时间 0.169 s
提交时间 2017-01-28 17:51:28 内存使用 4.89 MiB
显示代码纯文本
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
const LL maxn=150000;
LL sum[maxn];
LL n,m;
struct Bit{
	LL c[maxn][3];
	LL Lowbit(LL x){return x&-x;}
	void Update(LL op,LL x,LL add){
		for(LL i=x;i<=n;i+=Lowbit(i)){
			c[i][op]+=add;
		}
	}
	void Add(LL x,LL y,LL k){
		Update(1,x,k);Update(1,y+1,-k);
		Update(2,x,x*k);Update(2,y+1,-(y+1)*k);
	}
	LL Sum(LL op,LL x){
		LL res=0;
		for(LL i=x;i;i-=Lowbit(i)){
			res+=c[i][op];
		}
		return res;
	}
	LL Query(LL x,LL y){
		LL res=(y+1)*Sum(1,y)-Sum(2,y);
		res-=x*Sum(1,x-1)-Sum(2,x-1);
		res+=sum[y]-sum[x-1];
		return res;
	}

}BIT;
inline void read(LL & x){
	bool f=1;char ch;
	while(ch=getchar(),(ch>'9'||ch<'0')&&ch!='-');
	if(ch=='-'){ch=getchar();f=-1;}x=ch-'0';
	while(ch=getchar(),ch<='9'&&ch>='0')x=x*10+ch-'0';
	if(f==-1)x=-x;
}
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'){
			read(x);read(y);
			printf("%lld\n",BIT.Query(x,y));
		}
		else{
			read(x);read(y);read(k);
			scanf("%lld%lld%lld",&x,&y,&k);
			BIT.Add(x,y,k);
		}
	}
}