'commit'
This commit is contained in:
44
TangDou/AcWing/BIT/243_SZSZ_2.cpp
Normal file
44
TangDou/AcWing/BIT/243_SZSZ_2.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 1000010;
|
||||
typedef long long LL;
|
||||
|
||||
int n, m;
|
||||
LL a[N];
|
||||
|
||||
LL c1[N], c2[N];
|
||||
#define lowbit(x) (x & -x)
|
||||
void add(LL c[], LL x, LL v) {
|
||||
while (x < N) c[x] += v, x += lowbit(x);
|
||||
}
|
||||
LL sum(LL c[], LL x) {
|
||||
LL res = 0;
|
||||
while (x) res += c[x], x -= lowbit(x);
|
||||
return res;
|
||||
}
|
||||
LL query(LL x) {
|
||||
return sum(c1, x) * (x + 1) - sum(c2, x);
|
||||
}
|
||||
|
||||
int main() {
|
||||
scanf("%d%d", &n, &m);
|
||||
for (int i = 1; i <= n; i++) {
|
||||
scanf("%lld", &a[i]);
|
||||
add(c1, i, a[i]), add(c1, i + 1, -a[i]);
|
||||
add(c2, i, a[i] * i), add(c2, i + 1, -(i + 1) * a[i]);
|
||||
}
|
||||
while (m--) {
|
||||
char op[110];
|
||||
int i, j, d;
|
||||
scanf("%s", op);
|
||||
if (op[0] == 'Q') {
|
||||
scanf("%d%d", &i, &j);
|
||||
printf("%lld\n", query(j) - query(i - 1));
|
||||
} else {
|
||||
scanf("%d%d%d", &i, &j, &d);
|
||||
add(c1, i, d), add(c1, j + 1, -d);
|
||||
add(c2, i, d * i), add(c2, j + 1, -(j + 1) * d);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user