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;
    }
  • 相关阅读:
    Fody is only supported on MSBuild 16 and above
    abp发送邮件AbpMailKit
    看一位老司机的博文,分享一下。
    nginx PC 移动配置
    微信开放平台登录
    flask 中 session的源码解析
    python mac环境搭建
    前端换mac可以参考搭一下简单的环境
    vue 导航钩子
    HTML5 History 模式
  • 原文地址:https://www.cnblogs.com/bombe1013/p/4363307.html
Copyright © 2011-2022 走看看