题解
三维树状数组的区间更新、单点查询。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 101;
int c[maxn][maxn][maxn];
int n, m;
int lowbit(int x) { return x & -x; }
void update(int x, int y, int z){
for(int i = x; i <= n; i += lowbit(i)){
for(int j = y; j <= n; j += lowbit(j)){
for(int k = z; k <= n; k += lowbit(k)) c[i][j][k]++;
}
}
}
int sum(int x, int y, int z){
int s = 0;
for(int i = x; i ; i -= lowbit(i)){
for(int j = y; j ; j -= lowbit(j)){
for(int k = z; k ; k -= lowbit(k)) s += c[i][j][k];
}
}
return s;
}
int main(){
#ifdef EXMY
freopen("data.in", "r", stdin);
#endif // EXMY
while(scanf("%d %d", &n, &m) != EOF){
int sign, x1, y1, z1, x2, y2, z2;
memset(c, 0, sizeof(c));
while(m--){
scanf("%d %d %d %d", &sign, &x1, &y1, &z1);
if(sign == 1){
scanf("%d %d %d", &x2, &y2, &z2);
update(x1, y1, z1);
update(x1, y1, z2 + 1);
update(x1, y2 + 1, z1);
update(x1, y2 + 1, z2 + 1);
update(x2 + 1, y1, z1);
update(x2 + 1, y1, z2 + 1);
update(x2 + 1, y2 + 1, z1);
update(x2 + 1, y2 + 1, z2 + 1);
}
else printf("%d\n", sum(x1, y1, z1) % 2);
}
}
return 0;
}