1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| const int maxn = 100000 + 10; int n, m; int A[maxn]; llong sum[maxn];
void init() { Set(A, 0); Set(sum, 0); }
class Fwick { public: llong C[2][maxn]; int n;
void clear() { memset(C, 0, sizeof(C)); }
void resize(int n) { this->n = n; }
llong ask(int k, int x) { llong ret = 0; while (x) { ret += C[k][x]; x -= lowbit(x); } return ret; }
void add(int k, int x, int d) { while (x <= n) { C[k][x] += d; x += lowbit(x); } } };
Fwick fwick;
int main() { freopen("input.txt", "r", stdin); init();
scanf("%d%d", &n, &m); _rep(i, 1, n) { scanf("%d", &A[i]); sum[i] = sum[i - 1] + A[i]; }
fwick.clear(); fwick.resize(n);
_for(i, 0, m) { char op[2]; scanf("%s", op);
if(op[0] == 'C') { // int l, r, d; scanf("%d%d%d", &l, &r, &d);
fwick.add(0, l, d); fwick.add(0, r + 1, -d);
fwick.add(1, l, l * d); fwick.add(1, r + 1, -(r + 1) * d); } else { // int l, r; scanf("%d%d", &l, &r); llong ans = sum[r] + (r + 1) * fwick.ask(0, r) - fwick.ask(1, r); ans -= (sum[l - 1] + l * fwick.ask(0, l - 1) - fwick.ask(1, l - 1)); printf("%lld\n", ans); } } }
|