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. linux 不常用命令及命令组合

    lsof:list open files, sudo lsof | grep deleted:则列出虽然被删除,但还处于打开状态的文件.注意,这些文件占用的空间,只有在这些文件关闭时,才会被释放. m ...

  2. js数组去重的常用方法总结

    最近几天朋友面试了几家,笔试题都做了关于数组去重的问题,自己在网上收集整理了一些去重的方法来学习下,感觉换不错哈!!!第一种方法: function oSort(arr){ var n = []; / ...

  3. mysql 5.6 安装教程

    首先是下载 mysql-installer-community-5.6.14.0.msi ,大家可以到 mysql 官方网去下载,也可以到笔者所提供的地址去下载,下载方法在这里就不多说了,我想大家都明 ...

  4. 运输层协议——UDP

    UDP概述: UDP只是做了运输层协议能做的最少工作,仅做了复用/分解,少量的差错检验. UDP是无连接的. UDP优点: 关于何时.发送什么数据的应用层控制更为精细:TCP在拥堵时会遏制发送方的发送 ...

  5. 阿里&163 yum源

    站点:https://opsx.alibaba.com/mirror #阿里云base cat /etc/yum.repos.d/alibase.repo [rhel7] name=ali-base ...

  6. SQL解析器的性能測试

    对同一个sql语句,使用3种解析器解析出ast语法树(这是编译原理上的说法,在sql解析式可能就是解析器自己定义的statement类型).运行100万次的时间对照. package demo.tes ...

  7. 使用 Facebook开源动画库 POP 实现真实衰减动画

    1. POP动画基于底层刷新原理.是基于CADisplayLink,1秒钟运行60秒,接近于游戏开发引擎 @interface ViewController () @property (nonatom ...

  8. tensorflow 语法及 api 使用细节

    1. tf.nn.conv2d 的参数 padding='SAME' ⇒ 卷积之前的大小和卷积之后的大小一致,默认使用全 0 填充: padding='VALID' ⇒ 也即仅适用其有效部分,而不使用 ...

  9. 懒加载js实现和优化

    1.懒加载的作用和原理 在我们展示多图片的场景下,类似淘宝或者百度图片,由于图片的数目过多,全部从服务器请求会给用户糟糕的用户体验,为了提升用户体验,我们这里使用懒加载,随着下拉逐步加载. 每个图片的 ...

  10. js中常用的对象—Math的属性和方法

    js中有一个内置对象——Math对象,在有的时候非常有用,我们来分析一下: Math常用属性(注意要大写): E 返回算术常量 e,即自然对数的底数(约等于2.718)LN2 返回 2 的自然对数(约 ...