* 线段树所有操作合集 *
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL N = 2e6+10;
LL n , m ;
LL w[N] , ll[N] , rr[N] , tt[N];
struct Node{
LL l , r;
LL sum , lz_add ;
}tr[N<<2];
void merge(Node &u , Node l , Node r){
u.sum = l.sum + r.sum;
}
void lzdown(Node &u , Node &l , Node &r){
if(u.lz_add){
l.lz_add += u.lz_add , l.sum += (l.r - l.l + 1)*u.lz_add;
r.lz_add += u.lz_add , r.sum += (r.r - r.l + 1)*u.lz_add;
u.lz_add = 0;
}
}
void pushup(int u){
merge(tr[u] , tr[u<<1] , tr[u<<1|1]);
}
void pushdown(int u){
lzdown(tr[u] , tr[u<<1] , tr[u<<1|1]);
}
void init_leaf(Node &le){
LL x = le.l;
le.sum = w[x];
le.lz_add = 0;
}
void build(LL u , LL l ,LL r){
tr[u] = { l , r};
if(l == r) {
init_leaf(tr[u]);
return;
}
LL mid = l + r >> 1;
build(u<<1 , l , mid) , build(u<<1|1 , mid + 1 , r);
//merge(tr[u] , tr[u<<1] , tr[u<<1|1]);
pushup(u);
}
void modify_point(LL u , LL x ){
if(tr[u].l == x && tr[u].r == x){
init_leaf(tr[u]);
return;
}
LL mid = tr[u].l + tr[u].r >> 1;
if(x <= mid ) modify_point(u << 1 , x );
else modify_point(u << 1 | 1 , x );
// merge(tr[u] , tr[u<<1] , tr[u<<1|1]);
pushup(u);
}
void modify_seq(int u ,int l , int r , LL d){
if(l <= tr[u].l && tr[u].r <= r){
tr[u].lz_add += d;
tr[u].sum += (tr[u].r - tr[u].l + 1)*d;
return;
}
pushdown(u);
LL mid = tr[u].l + tr[u].r >> 1;
if(l <= mid ) modify_seq(u<<1 , l , r , d);
if(r > mid) modify_seq(u<<1|1 , l , r, d);
pushup(u);
}
Node query(LL u , LL l , LL r){
if(l <= tr[u].l && tr[u].r <= r){
return tr[u];
}
pushdown(u);
LL mid = tr[u].l + tr[u].r >> 1;
if( l > mid ) return query(u<<1|1 , l , r);
else if( r <= mid) return query(u<<1 ,l ,r);
else{
auto le = query(u<<1 ,l , r);
auto re = query(u<<1|1 , l , r);
Node res;
merge(res ,le ,re);
return res;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);//输入加速
cout.tie(0);//输出加速
cin>>n>>m;
for(int i = 1; i <= n ; i ++) cin>>w[i];
build(1 , 1 , n);
string s;
while(m--){
cin>>s;
if(s[0] == 'C'){
int l , r ,d;
cin>>l >> r>>d;
modify_seq(1 , l , r , d);
}
else{
int l , r;
cin>>l>>r;
cout<<query(1 , l , r).sum<<endl;
}
}
}