#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long int LL;
const int maxn=1e5;
int rt[maxn*35+5];
int ls[maxn*35+5];
int rs[maxn*35+5];
int p;
LL sum[maxn*35+5];
LL pos[maxn*35+5];
int n,m,t;
int newnode()
{
ls[p]=rs[p]=sum[p]=pos[p]=0;
return p++;
}
void build(int &node,int begin,int end)
{
if(!node) node=newnode();
if(begin==end)
{
scanf("%lld",&sum[node]);
return;
}
int mid=(begin+end)>>1;
build(ls[node],begin,mid);
build(rs[node],mid+1,end);
sum[node]=sum[ls[node]]+sum[rs[node]];
}
void update(int &node,int begin,int end,int left,int right,int val)
{
sum[p]=sum[node];ls[p]=ls[node];rs[p]=rs[node];
pos[p]=pos[node];
node=p;p++;
sum[node]+=1LL*val*(right-left+1);
if(left==begin&&end==right)
{
pos[node]+=val;
return;
}
int mid=(begin+end)>>1;
if(right<=mid) update(ls[node],begin,mid,left,right,val);
else if(left>mid) update(rs[node],mid+1,end,left,right,val);
else
{
update(ls[node],begin,mid,left,mid,val);
update(rs[node],mid+1,end,mid+1,right,val);
}
}
LL query(int node,int begin,int end,int left,int right)
{
if(left<=begin&&end<=right) return sum[node];
LL ret=1LL*pos[node]*(right-left+1);
int mid=(begin+end)>>1;
if(right<=mid) ret+=query(ls[node],begin,mid,left,right);
else if(left>mid) ret+=query(rs[node],mid+1,end,left,right);
else
{
ret+=(query(ls[node],begin,mid,left,mid)+query(rs[node],mid+1,end,mid+1,right));
}
return ret;
}
int main()
{
char x;
while(scanf("%d%d",&n,&m)!=EOF)
{
t=0;
p=0;
build(rt[0],1,n);
int l,r,d,time;
LL ans;
for(int i=1;i<=m;i++)
{
cin>>x;
if(x=='C')
{
scanf("%d%d%d",&l,&r,&d);
update(rt[++t]=rt[t-1],1,n,l,r,d);
}
else if(x=='Q')
{
scanf("%d%d",&l,&r);
ans=query(rt[t],1,n,l,r);
printf("%lld\n",ans);
}
else if(x=='H')
{
scanf("%d%d%d",&l,&r,&time);
ans=query(rt[time],1,n,l,r);
printf("%lld\n",ans);
}
else
{
scanf("%d",&time);
t=time;
}
}
}
return 0;
}