zoukankan      html  css  js  c++  java
  • 【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;
    }
  • 相关阅读:
    Alpha冲刺Day10
    Alpha冲刺Day9
    Alpha冲刺Day8
    Alpha冲刺Day7
    Alpha冲刺Day6
    SDN
    【Alpha
    【Alpha】团队课程展示
    【Alpha】团队项目测试报告与用户反馈
    【Alpha】总结
  • 原文地址:https://www.cnblogs.com/bombe1013/p/4363307.html
Copyright © 2011-2022 走看看