小小树状数组 为什么CE了
#include <bits/stdc++.h>
using namespace std;
int n, m, q, op, x1, y1, x2, y2, x, y, c;
const int N = 305, C = 105;
int a[N][N], tree[N][N][C];
int lowbit(int x) {
return x & (-x);
}
void add_single(int x, int y, int color, int num) {
for(int i = x; i <= n; i += lowbit(i))
for(int j = y; j <= m; j += lowbit(j))
tree[i][j][color] += num;
}
int ask(int x, int y, int color) {
int ret = 0;
for(int i = x; i; i -= lowbit(i))
for(int j = y; j; j -= lowbit(j))
ret += tree[i][j][color];
return ret;
}
int search(int x1, int y1, int x2, int y2, int color) {
return ask(x2, y2, color) - ask(x2, y1 - 1, color) - ask(x1 - 1, y2, color) + ask(x1 - 1, y1 - 1, color);
}
int main() {
cin >> n >> m;
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++) {
cin >> a[i][j];
add_single(i, j, a[i][j], 1);
}
cin >> q;
while(q --) {
cin >> op;
if(op == 1) {
cin >> x >> y >> c;
add_single(x, y, a[x][y], -1);
a[x][y] = c;
add_single(x, y, a[x][y], 1);
} else {
cin >> x1 >> x2 >> y1 >> y2 >> c;
cout << search(x1, y1, x2, y2, c) << endl;
}
}
}