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 Cube --三维树状数组

    题意:给一个三维数组n*n*n,初始都为0,每次有两个操作: 1. 翻转(x1,y1,z1) -> (x2,y2,z2) 0. 查询A[x][y][z] (A为该数组) 解法:树状数组维护操作次 ...

  2. HDU - 3584 Cube (三维树状数组 + 区间改动 + 单点求值)

    HDU - 3584 Cube Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Subm ...

  3. HDU 3584 Cube 【 三维树状数组 】

    题意:还是那篇论文里面讲到的,三维树状数组http://wenku.baidu.com/view/1e51750abb68a98271fefaa8画个立方体出来对照一下好想一点 #include< ...

  4. HDU 3584 三维树状数组

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

  5. 1470. UFOs(三维树状数组)

    1470 最简单的三维树状数组 #include <iostream> #include<cstdio> #include<cstring> #include< ...

  6. 暴力三维树状数组求曼哈顿距离求最值——牛客多校第八场D

    涉及的知识点挺多,但是大多是套路 1.求曼哈顿距离的最值一般对所有情况进行讨论 2.三维树状数组用来求前缀最大值 /* 有一个三维坐标系(x,y,z),取值范围为[1,n],[1,m],[1,h],有 ...

  7. HDU 3333 | Codeforces 703D 树状数组、离散化

    HDU 3333:http://acm.hdu.edu.cn/showproblem.php?pid=3333 这两个题是类似的,都是离线处理查询,对每次查询的区间的右端点进行排序.这里我们需要离散化 ...

  8. HDU 3333 - Turing Tree (树状数组+离线处理+哈希+贪心)

    题意:给一个数组,每次查询输出区间内不重复数字的和. 这是3xian教主的题. 用前缀和的思想可以轻易求得区间的和,但是对于重复数字这点很难处理.在线很难下手,考虑离线处理. 将所有查询区间从右端点由 ...

  9. HDU 3333 Turing Tree (树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3333 题意就是询问区间不同数字的和. 比较经典的树状数组应用. //#pragma comment(l ...

随机推荐

  1. 在Unix上用 BIND建立名称服务器(naem server)

    在Unix上用 BIND建立名称服务器(naem server) 安装 apt install -y bind9 yum install -y bind bind-utils 下载源码并解压缩,htt ...

  2. linux关于用户密码家目录总结

    创建用户及其家目录useradd -d /home/tomcat -m tomcat接着修改密码passwd tomcat usermod -s /sbin/nologin + 用户名 禁止登录ssh ...

  3. Integer 和 int的种种比较

    public static void main(String[] args) { int i = 128; Integer i2 = 128; Integer i3 = new Integer(128 ...

  4. SpringMVC+MyBatis (druid、logback)

    数据库连接池是阿里巴巴的druid.日志框架式logback 1.整合SpringMVCspringMybatis-servlet.xml: <?xml version="1.0&qu ...

  5. Sqoop 数据导入导出实践

    Sqoop是一个用来将hadoop和关系型数据库中的数据相互转移的工具,可以将一个关系型数据库(例如:mysql,oracle,等)中的数据导入到hadoop的HDFS中,也可以将HDFS的数据导入到 ...

  6. 洛谷P1200 [USACO1.1]你的飞碟在这儿

    题目描述 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支持者.因此,他们要用一种聪明的方案让这些小组提前知道谁会被彗星带走 ...

  7. try/catch的用法

    1.try/catch用法基础介绍 try { //程序中抛出异常 throw value; } catch(valuetype v) { //例外处理程序段 } 语法小结:throw抛出值,catc ...

  8. Lightroom 学习笔记

    16.8.28  白平衡:      夕阳照片,色温高大

  9. python 深浅拷贝小记

    浅拷贝:只拷贝第一层的数据 深拷贝:相当于克隆 一份,也就是完全复制,和被克隆对象完全没关系. 浅拷贝示例:先定义一个列表 >>> s = [1,'alex','alvin'] &g ...

  10. qt获取磁盘序列号

    #include "windows.h" QString lpRootPathName = "c:\\"; LPTSTR lpVolumeNameBuffer= ...