【HDOJ】5057 Argestes and Sequence

时间:2022-05-28 20:05:21

树状数组,其实很简单。只是MLE。

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; #define MAXN 100005 short sum[][][MAXN];
char bit[][][MAXN];
int a[MAXN];
int t, n, m;
int d, p;
const int MOD = ; int lowbit(int x) {
return x & -x;
} int getSum(int x, int d, int p) {
int ret = ;
while (x > ) {
ret += (int)sum[d][p][x] + ((int)bit[d][p][x]) * MOD;
x -= lowbit(x);
}
return ret;
} void update(int x, int d, int p, int r) {
int tmp;
while (x <= n) {
tmp = (int)sum[d][p][x] + r;
sum[d][p][x] = tmp%MOD;
bit[d][p][x] += tmp/MOD;
x += lowbit(x);
}
} int query(int l, int r) {
return getSum(r, d-, p) - getSum(l-, d-, p);
} void insert(int x, int i, int delta) {
int j;
for (j=; j<=; ++j) {
update(i, j-, x%, delta);
x /= ;
}
} int main() {
int i, j, ans;
int x, y;
char cmd[]; scanf("%d", &t);
while (t--) {
scanf("%d %d", &n, &m);
for(i=; i<; i++) {
for(j=; j<; j++) {
memset(sum[i][j], , sizeof(short)*(n+));
memset(bit[i][j], , sizeof(char)*(n+));
}
}
for (i=; i<=n; ++i) {
scanf("%d", &a[i]);
insert(a[i], i, );
}
while (m--) {
scanf("%*c%s %d %d", cmd, &x, &y);
if (cmd[] == 'S') {
insert(a[x], x, -);
a[x] = y;
insert(a[x], x, );
} else {
scanf("%d %d", &d, &p);
ans = query(x, y);
printf("%d\n", ans);
}
}
} return ;
}