| 记录编号 |
367130 |
评测结果 |
AAAAAAAAAA |
| 题目名称 |
1317.数列操作C |
最终得分 |
100 |
| 用户昵称 |
Go灬Fire |
是否通过 |
通过 |
| 代码语言 |
C++ |
运行时间 |
0.163 s |
| 提交时间 |
2017-01-28 16:45:43 |
内存使用 |
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];
int n,m;
int Lowbit(int x){
return x&-x;
}
LL Query(LL *arr,int x){
LL res=0;
for(int i=x;i;i-=Lowbit(i))res+=arr[i];
return res;
}
void Add(LL *arr,int x,LL add){
for(int 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("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lld",&sum[i]);
sum[i]+=sum[i-1];
}
scanf("%d",&m);
for(int i=1;i<=m;i++){
char type[6];scanf("%s",type);
int x,y,k;
if(type[0]=='S'){
scanf("%d%d",&x,&y);
LL sumr=sum[y]+1ll*(y+1)*Query(c,y)-Query(cc,y);
LL suml=sum[x-1]+1ll*(x-1+1)*Query(c,x-1)-Query(cc,x-1);
printf("%lld\n",sumr-suml);
}
else{
scanf("%d%d%d",&x,&y,&k);
Add(c,x,k);Add(c,y+1,-k);
Add(cc,x,1ll*x*k);Add(cc,y+1,-1ll*(y+1)*k);
}
}
}