【HDOJ】3584 Cube

三位树状数组。

/* 3584 */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std;

#define MAXN 105

bool cnt[MAXN][MAXN][MAXN];
int n, m;

inline int lowest(int x) {
    return x&-x;
}

bool sum(int x, int y, int z) {
    int i, j, k;
    int ret = 0;
    
    for (i=x; i; i-=lowest(i)) {
        for (j=y; j; j-=lowest(j)) {
            for (k=z; k; k-=lowest(k)) {
                ret += cnt[i][j][k];
            }
        }
    }
    return (ret&1) ? true:false;
}

void update(int x, int y, int z) {
    int i, j, k;
    
    for (i=x; i<=n; i+=lowest(i)) {
        for (j=y; j<=n; j+=lowest(j)) {
            for (k=z; k<=n; k+=lowest(k)) {
                cnt[i][j][k] = !cnt[i][j][k];
            }
        }
    }
}

int main() {
    int i, j, k;
    int x1, y1, z1, x2, y2, z2;
    
    #ifndef ONLINE_JUDGE
        freopen("data.in", "r", stdin);
        freopen("data.out", "w", stdout);
    #endif
    
    while (scanf("%d %d", &n, &m)!=EOF) {
        memset(cnt, false, sizeof(cnt));
        while (m--) {
            scanf("%d", &i);
            if (i) {
                scanf("%d%d%d%d%d%d", &x1,&y1,&z1, &x2,&y2,&z2);
                update(x1, y1, z1);
                update(x1, y1, z2+1);
                update(x1, y2+1, z2+1);
                update(x1, y2+1, z1);
                update(x2+1, y1, z1);
                update(x2+1, y1, z2+1);
                update(x2+1, y2+1, z2+1);
                update(x2+1, y2+1, z1);
            } else {
                scanf("%d %d %d", &x1, &y1, &z1);
                k = sum(x1, y1, z1);
                if (k)
                    puts("1");
                else
                    puts("0");
            }
        }
    }
    
    return 0;
}

 

posted on 2015-03-24 16:49  Bombe  阅读(126)  评论(0编辑  收藏  举报

导航