hdoj--3584 Cube(三维树状数组)

来源:互联网 发布:java飞机大战子弹 编辑:程序博客网 时间:2024/06/05 00:18

3584 Cube

题解

三维树状数组的区间更新、单点查询。

#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 EXMYfreopen("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;}
0 0
原创粉丝点击