题目传送门
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdlib.h>
#include <queue>
#include <map>
#include <iomanip>
#include <math.h>
using namespace std;
typedef long long LL;
#define lowbit(x) x &(-x)
const int N = 2e5 + 10;
LL t1[N], t2[N];
LL n, m, a[N];
LL add(LL x, LL y) {
for (LL i = x; i <= n; i += lowbit(i)) {
t1[i] += y;
t2[i] += x * y;
}
}
LL ask(LL x) {
LL ans = 0;
for (LL i = x; i; i -= lowbit(i)) ans += (x + 1) * t1[i] - t2[i];
return ans;
}
int main() {
scanf("%lld %lld\n", &n, &m);
for (LL i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
add(i, a[i]);
add(i + 1, -a[i]);
}
while (m--) {
char ch[2];
scanf("%s", ch);
if (ch[0] == 'Q') {
LL x, y;
scanf("%lld %lld\n", &x, &y);
cout << ask(y) - ask(x - 1) << endl;
}
if (ch[0] == 'C') {
LL x, y, d;
scanf("%lld %lld %lld\n", &x, &y, &d);
add(x, d);
add(y + 1, -d);
}
}
return 0;
}