Problem Description
Given an N*N*N cube A, whose elements are either 0 or 1. A[i, j, k] means the number in the i-th row , j-th column and k-th layer. Initially we have A[i, j, k] = 0 (1 <= i, j, k <= N).
We define two operations, 1: “Not” operation that we change the A[i, j, k]=!A[i, j, k]. that means we change A[i, j, k] from 0->1,or 1->0. (x1<=i<=x2,y1<=j<=y2,z1<=k<=z2).
0: “Query” operation we want to get the value of A[i, j, k].
Input
Multi-cases.
First line contains N and M, M lines follow indicating the operation below.
Each operation contains an X, the type of operation. 1: “Not” operation and 0: “Query” operation.
If X is 1, following x1, y1, z1, x2, y2, z2.
If X is 0, following x, y, z.
Output
For each query output A[x, y, z] in one line. (1<=n<=100 sum of m <=10000)
Sample Input
2 5 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 2 2 2 0 1 1 1 0 2 2 2
Sample Output
1 0 1

三维树状数组。

加一个for循环就ok

#include <iostream>
#include <cstring>
#include <cstdio>
//#include <cmath>
#include <set>
#include <stack>
#include <cctype>
#include <algorithm>
#define lson o<<1, l, m
#define rson o<<1|1, m+1, r
using namespace std;
typedef long long LL;
const int mod = 99999997;
const int MAX = 1000000000;
const int maxn = 1005;
int n, q, x1, y1, z1, x2, y2, z2, op;
int c[101][101][101];
void add(int x, int y, int z) {for(int i = x; i <= n; i += i&-i)for(int j = y; j <= n; j += j&-j)for(int k = z; k <= n; k += k&-k)c[i][j][k]++;
}
int query(int x, int y, int z) {int sum = 0;for(int i = x; i > 0; i -= i&-i)for(int j = y; j > 0; j -= j&-j)for(int k = z; k > 0; k -= k&-k)sum += c[i][j][k];return sum;
}
int main()
{//freopen("in.txt", "r", stdin);while(cin >> n >> q) {memset(c, 0, sizeof(c));while(q--) {scanf("%d%d%d%d", &op, &x1, &y1, &z1);if(op) {scanf("%d%d%d", &x2, &y2, &z2);x2++, y2++, z2++;add(x1, y1, z1);add(x1, y1, z2);add(x1, y2, z1);add(x2, y1, z1);add(x1, y2, z2);add(x2, y1, z2);add(x2, y2, z1);add(x2, y2, z2);} else printf("%d\n", query(x1, y1, z1) & 1);}}return 0;
}


HDU 3584 Cube (三维树状数组)相关推荐

  1. HDU 3584 三维树状数组

    三维树状数组模版.优化不动了. #include <set> #include <map> #include <stack> #include <cmath& ...

  2. HDU ACM 4031 Attack (树状数组--单点查询+区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=4031 用了树状数组的区间更新 单点查找(一般为单点更新 区间查找) 例如 区间(2,4)加1 则Updata(2 ...

  3. hdu 4125 Moles(kmp+树状数组)

    题目链接:hdu 4125 Moles 题意: 给你n个数,让你按键值建一个平衡二叉树,然后奇数为0,偶数为1,然后可以遍历这颗树得到一个欧拉序列,现在给你一个串,问你出现了几次. 题解: 建树的时候 ...

  4. hdu 1892二维树状数组

    这题我知道是用树状数组,可是好久没打树状数组了,就想用普通方法水过去~~结果--结果--水了好多方法都水不过,出题人真狠呐--我的水方法是对于每一次查询,初始化ans=(x2-x1+1)*(y2-y1 ...

  5. hdu 4417 Super Mario 树状数组||主席树

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Prob ...

  6. HDU 1556 前缀和 树状数组 线段树

    解法一: a[i]表示以 i作为起点,对 i-n的气球全部上色的次数  对(start,end)区间上色 ++a[start] --a[end+1]抵消掉 end+1-n的部分 问题转换为求 a的前缀 ...

  7. HDU - 5775 Bubble Sort(树状数组)

    题目链接:点击查看 题目大意:给出n个数,求出按照冒泡排序期间每个数可以到达的最右边位置和最左边位置的差 题目分析:其实这个题想明白了就很简单了,先用辅助数组a按照顺序存储每一个数,a[i]就代表排序 ...

  8. HDU 4777 Rabbit Kingdom 树状数组

    分析:找到每一个点的左边离他最近的不互质数,记录下标(L数组),右边一样如此(R数组),预处理 这个过程需要分解质因数O(n*sqrt(n)) 然后离线,按照区间右端点排序 然后扫一遍,对于当前拍好顺 ...

  9. hdu 4267 多维树状数组

    题意:有一个序列 "1 a b k c" means adding c to each of Ai which satisfies a <= i <= b and (i ...

最新文章

  1. 使用SQL Server维护计划实现数据库定时自动备份
  2. java与javascript之间json格式数据互转
  3. 国家服务器1eb硬盘,仅一个月:奇亚币已占用超过1EB存储空间
  4. 【vijos】【二叉树】FBI树
  5. React学习:事件绑定、组件定义、for、map循环-学习笔记
  6. 实战:ajax带参数请求slim API
  7. TCP close_wait内幕
  8. php CSRF攻击与防御
  9. SSH key的生成及使用
  10. Bom及Bom对象的详细介绍
  11. 手机测试移动网速的软件,移动测试网速(中国移动在线测速)
  12. 利用selenium下载图片,不使用requests和urllib等其他工具
  13. python批量导入excel中的IP地址查询所在地及运营商
  14. Lenovo UEFI引导U盘 System x Install Windows Server 2016 R2
  15. u盘中毒文件被隐藏恢复方法
  16. vue--实现跑马灯效果
  17. 「用ChatGPT搞钱年入百万!」各路博主发布生财之道,网友回呛:答辩的搬运工...
  18. andorid 问题集合
  19. 圆圈中最后剩下的数字 ----《剑指offer》面试题45
  20. XSS Challenges闯关1-6

热门文章

  1. 深度学习已经触底?这篇文章的观点令人信服吗?
  2. 2018世界人工智能蓝皮书:看中国到底有多强!【附下载】| 智东西内参
  3. AI大神Yann LeCun谈近期AI发展:最聪明的AI在常识方面还不如猫
  4. 2018全球100个最有价值的科技品牌 18个中国品牌上榜
  5. 2018年智能化发展趋势:语音交互全球开战、AI终端趋势显现
  6. 华为《5G业务商业价值评估》白皮书!
  7. 要毁灭人类、喷马斯克、还获得公民身份的Sophia,是假的
  8. 300 多行代码搞定微信 8.0 的「炸」「裂」特效!
  9. ML.NET 0.2版增加了集群和新示例
  10. 用机器学习做信用评分