记录编号 |
574917 |
评测结果 |
AAAAAAAAAAAAAAA |
题目名称 |
数列操作B |
最终得分 |
100 |
用户昵称 |
瑆の時間~無盡輪迴·林蔭 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
3.095 s |
提交时间 |
2022-08-28 22:48:52 |
内存使用 |
589.26 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#define int long long int
using namespace std;
const int N=1000011,LOG=20;
int L[N*LOG],R[N*LOG],sum[N*LOG],rt[N],lazy[N*LOG];
int a[N],rts=0,n,m;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
void pushup(int x)
{
sum[x]=sum[L[x]]+sum[R[x]];
}
int build(int l,int r)
{
int x=++rts;
if(l==r)
{
sum[x]=a[l];
return x;
}
int mid=(l+r)>>1;
L[x]=build(l,mid);
R[x]=build(mid+1,r);
pushup(x);
return x;
}
int Change(int be,int l,int r,int pos,int k)
{
int x=++rts;
if(l==r)
{
sum[x]=k;
return x;
}
L[x]=L[be];
R[x]=R[be];
int mid=(l+r)>>1;
if(pos<=mid)
L[x]=Change(L[be],l,mid,pos,k);
else
R[x]=Change(R[be],mid+1,r,pos,k);
pushup(x);
return x;
}
int Query(int x,int l,int r,int k)
{
if(l==r)
{
return sum[x];
}
int mid=(l+r)>>1;
if(k<=mid)
return Query(L[x],l,mid,k)+lazy[x];
else
return Query(R[x],mid+1,r,k)+lazy[x];
}
int QJJ(int be,int l,int r,int nl,int nr,int k)
{
int x=++rts;
sum[x]=sum[be];
lazy[x]=lazy[be];
L[x]=L[be];
R[x]=R[be];
if(nl<=l&&nr>=r)
{
sum[x]+=(r-l+1)*k;
lazy[x]+=k;
return rts;
}
int mid=(l+r)>>1;
if(nl<=mid)
{
L[x]=QJJ(L[be],l,mid,nl,nr,k);
}
if(nr>mid)
{
R[x]=QJJ(R[be],mid+1,r,nl,nr,k);
}
pushup(x);
return x;
}
signed main()
{
freopen("shulieb.in","r",stdin);
freopen("shulieb.out","w",stdout);
n=read();
for(int i=1;i<=n;i++)
a[i]=read();
m=read();
int a1,a2,a3,a4;
rt[0]=build(1,n);
int lastad=0;
string x;
for(int i=1;i<=m;i++)
{
cin>>x;
if(x=="QUERY")
{
a1=read();
rt[i]=rt[i-1];
cout<<Query(rt[i-1],1,n,a1)<<endl;
}
else
{
a1=read();
a2=read();
a3=read();
rt[i]=QJJ(rt[i-1],1,n,a1,a2,a3);
}
}
return 0;
}