#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; ll value[N<<],lazy[N<<];
void build(int l,int r,int rt)
{
lazy[rt]=;
if(l==r)
{
scanf("%lld",&value[rt]);
return ;
}
int m=(l+r)>>;
build(ls);
build(rs);
value[rt]=value[rt<<]+value[rt<<|];
}
void update(int L,int R,ll c,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
lazy[rt]+=c;
//value[rt]+=c*(r-l+1);
return ;
}
int m=(l+r)>>;
if(L<=m)update(L,R,c,ls);
if(m<R)update(L,R,c,rs);
value[rt]=value[rt<<]+value[rt<<|]+lazy[rt<<]*(m-l+)+lazy[rt<<|]*(r-m);
}
ll query(int L,int R,ll add,int l,int r,int rt)
{
if(L<=l&&r<=R)
return (add+lazy[rt])*(r-l+)+value[rt];
int m=(l+r)>>;
ll ans=;
if(L<=m)ans+=query(L,R,add+lazy[rt],ls);
if(m<R)ans+=query(L,R,add+lazy[rt],rs);
return ans;
}
char s[];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
build(,n,);
while(m--)
{
scanf("%s",s);
if(s[]=='Q')
{
int l,r;
scanf("%d%d",&l,&r);
printf("%lld\n",query(l,r,,,n,));
}
else
{
int l,r;ll c;
scanf("%d%d%lld",&l,&r,&c);
update(l,r,c,,n,);
//printf("%d\n",query(1,n,0,1,n,1));
}
}
}
return ;
}
/********************
5
10000
1 1 1 1 1
w 1 3 2
w 2 4 3
w 1 5 1
********************/
标记永久化