/*
a是原数组,b是a的差分数组, b[i] = a[i] - a[i - 1], a[i] = b[1] + b[2] + ... + b[i];
b1 b2 b3 ... bx
b1 b2 b3 ... bx
.
.
.
b1 b2 b3 ... bx
一共x+1项
求a的前缀和:
sum(a[1~x]) = b1 + (b1 + b2) + ... (b1 + b2 + ... + bx)
由上图的矩阵可知:
sum(a[1~x]) = sum(b[1~x] * (x+1) - (b1 + 2*b2 + 3*b3 + ... + x*bx)
因此可以用两个树状数组来分别维护 b 和 b[i]*i
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 100010;
int n, m;
LL tr1[N];//维护差分数组
LL tr2[N];//维护b[i] * i的前缀和
int a[N];
int lowbit(int x)
{
return x & -x;
}
void add(LL tr[], int x, LL c)
{
for (int i = x; i <= n; i += lowbit(i)) tr[i] += c;
}
LL sum(LL tr[], int x)
{
LL res = 0;
for (int i = x; i; i -= lowbit(i)) res += tr[i];
return res;
}
LL prefix_sum(int x)
{
return sum(tr1, x) * (x + 1) - sum(tr2, x);
}
int main()
{
scanf("%d%d",&n, &m);
for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i ++)
{
int b = a[i] - a[i - 1];
add(tr1, i, b);
add(tr2, i, (LL)b * i);
}
while(m --)
{
char op[2];
int l, r, d;
scanf("%s%d%d",op, &l, &r);
if (op[0] == 'Q')
{
printf("%lld\n", prefix_sum(r) - prefix_sum(l - 1));
}
else
{
scanf("%d", &d);
// a[l] += d
add(tr1, l, d), add(tr2, l, l * d);
// a[r + 1] -= d;
//b[r+1]*(r+1) -> (b[r+1]-d)*(r+1) 即 b[r+1]*d - d*(r+1)
add(tr1, r + 1, -d), add(tr2, r + 1, (r + 1) * -d);
}
}
return 0;
}