记录编号 |
534823 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
数列操作C |
最终得分 |
100 |
用户昵称 |
清雪榛子 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
2.192 s |
提交时间 |
2019-07-03 12:54:54 |
内存使用 |
17.47 MiB |
显示代码纯文本
#include<fstream>
#include<iostream>
#include<string>
using namespace std;
long long A[100001],c[100001],d[100001],d2[100001],c2[100001],n,m;
ifstream fin("shuliec.in");
ofstream fout("shuliec.out");
int lowbit(int a){
return a&(-a);
}
void build(long long k){
for(long long j=k;j<=n;j+=lowbit(j)) c[j]+=d[k];
}
void build2(long long k){
for(long long j=k;j<=n;j+=lowbit(j)) c2[j]+=d2[k];
}
void add(long long k,long long j,long long x){
for(long long i=k;i<=n;i+=lowbit(i)) c[i]+=x;
for(long long i=j;i<=n;i+=lowbit(i)) c[i]-=x;
}
void add2(long long k,long long j,long long x){
for(long long i=k;i<=n;i+=lowbit(i)) c2[i]+=x*k;
for(long long i=j;i<=n;i+=lowbit(i)) c2[i]-=x*j;
}
long long sum(long long k,long long ans){
for(long long i=k;i>0;i-=lowbit(i)) ans+=c[i];
return ans;
}
long long sum2(long long k,long long ans){
for(long long i=k;i>0;i-=lowbit(i)) ans+=c2[i];
return ans;
}
int main(){
string x;
fin>>n;
A[0]=0;
for(long long i=1;i<=n;i++){
fin>>A[i];
d[i]=A[i]-A[i-1];
d2[i]=d[i]*i;
build(i);
build2(i);
}
fin>>m;
for(long long i=0;i<m;i++){
fin>>x;
if(x=="SUM"){
long long a,b,t;
fin>>a>>b;
t=b;
b=sum(t,0)*(t+1);
b-=sum2(t,0);
t=a-1;
if(a==1) fout<<b<<endl;
else{
a=sum(t,0)*(t+1);
a-=sum2(t,0);
fout<<(b-a)<<endl;
}
}
else{
long long k,j,d;
fin>>k>>j>>d;
add2(k,j+1,d);
add(k,j+1,d);
}
}
return 0;
}