【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   Bombe  阅读(128)  评论(0编辑  收藏  举报

编辑推荐:
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
阅读排行:
· 为DeepSeek添加本地知识库
· 精选4款基于.NET开源、功能强大的通讯调试工具
· DeepSeek智能编程
· 大模型工具KTransformer的安装
· [计算机/硬件/GPU] 显卡
历史上的今天:
2014-03-24 【原创翻译】Reducing Branch Delay to Zero in Pipelined Processors
2014-03-24 【算法导论】学习笔记——第22章 图的基本算法
2014-03-24 【HDOJ】1253 胜利大逃亡
2014-03-24 【Python】代码行数统计
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

导航

统计

点击右上角即可分享
微信分享提示