记录编号 |
398409 |
评测结果 |
AAAAAAAAAA |
题目名称 |
数列操作C |
最终得分 |
100 |
用户昵称 |
sasasas |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.451 s |
提交时间 |
2017-04-22 10:44:56 |
内存使用 |
76.61 MiB |
显示代码纯文本
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define for1(a,b,i) for(int i=a;i<=b;i++)
#define sca(a,b) scanf("%d%d",&a,&b)
#define sc(a) scanf("%d",&a)
#define sclll(a) scanf("%lld",&a)
#define LL long long
const int M=1000000+5;
int n,m;
LL a[M],add[M];
string s;
struct tree{
int lc,rc;
LL sum;
}tr[4*M];
void pushup(int z)
{
tr[z].sum=tr[z<<1].sum+tr[(z<<1)+1].sum;
return;
}
void bt(int x,int y,int z)
{
int mid=(x+y)/2;
tr[z].rc=y;
tr[z].lc=x;
if(x==y)
{
tr[z].sum=a[x];
return ;
}
bt(x,mid,z<<1);
bt(mid+1,y,(z<<1)+1);
pushup(z);
}
void pushdown(int x,int y)
{
if(add[x])
{
add[x<<1]+=add[x];
add[(x<<1)+1]+=add[x];
tr[x<<1].sum+=add[x]*(LL)(y-(y>>1));
tr[(x<<1)+1].sum+=add[x]*(LL)(y>>1);
add[x]=0;
}
}
void change(int x,int y,int z,LL u)
{
if(tr[z].lc>=x&&tr[z].rc<=y)
{
add[z]+=u;
tr[z].sum+=u*(LL)(tr[z].rc-tr[z].lc+1);
return ;
}
pushdown(z,tr[z].rc-tr[z].lc+1);
int mid=(tr[z].rc+tr[z].lc)/2;
if(x<=mid)
change(x,y,z<<1,u);
if(mid<y)
change(x,y,(z<<1)+1,u);
pushup(z);
}
LL que(int x,int y,int z)
{
if(tr[z].lc>=x&&tr[z].rc<=y)
return tr[z].sum;
pushdown(z,tr[z].rc-tr[z].lc+1);
int mid=(tr[z].lc+tr[z].rc)>>1;
LL temp=0;
if(x<=mid)
temp+=que(x,y,z<<1);
if(mid<y)
temp+=que(x,y,(z<<1)+1);
return temp;
}
int read()
{
int su=0;
char ch=getchar();
while(ch<'0'||ch>'9')
ch=getchar();
while(ch<='9'&&ch>='0')
{
su=su*10+ch-'0';
ch=getchar();
}
return su;
}
int main()
{
freopen("shuliec.in","r",stdin);
freopen("shuliec.out","w",stdout);
sc(n);
for1(1,n,i)
sclll(a[i]);
bt(1,n,1);
sc(m);
for1(1,m,i)
{
cin>>s;
int x,y;LL z;
if(s[0]=='S')
{
sca(x,y);
printf("%lld\n",que(x,y,1));
continue;
}
if(s[0]=='A')
{
sca(x,y);scanf("%lld",&z);
change(x,y,1,z);
}
}
//while(1);
return 0;
}