HDU - 3584

Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

Submit Status

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
 
/*
Author: 2486
Memory: 5944 KB Time: 202 MS
Language: G++ Result: Accepted
VJ RunId: 4328542 Real RunId: 14413386
*/
//三维的与二维的一样,而二维的与一维的一样
//具体解释。本博客中解答了题目这么做的原理
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int MAXN = 100 + 5;
int C[MAXN][MAXN][MAXN];
int N, M; int lowbit(int x) {
return x & (-x);
} void add(int x, int y, int z) {
for(int i = x; i <= N; i += lowbit(i)) {
for(int j = y; j <= N; j += lowbit(j)) {
for(int k = z; k <= N; k += lowbit(k)) {
C[i][j][k] ++;
}
}
}
}
int query(int x, int y, int z) {
int ret = 0;
for(int i = x; i > 0 ; i -= lowbit(i)) {
for(int j = y; j > 0; j -= lowbit(j)) {
for(int k = z; k > 0; k -= lowbit(k)) {
ret += C[i][j][k];
}
}
}
return ret & 1;
}
int X, x, y, z, x1, y1, z1, x2, y2, z2;
int main() {
while(~ scanf("%d%d", &N, &M)) {
memset(C, 0, sizeof(C));
while(M --) {
scanf("%d", &X);
if(X) {
scanf("%d%d%d%d%d%d", &x1, &y1, &z1, &x2, &y2, &z2);
x2 ++;
y2 ++;
z2 ++;
add(x1, y1, z1);
add(x1, y2, z1);
add(x1, y1, z2);
add(x1, y2, z2);
add(x2, y1, z1);
add(x2, y2, z1);
add(x2, y1, z2);
add(x2, y2, z2);
} else {
scanf("%d%d%d", &x, &y, &z);
printf("%d\n", query(x, y, z));
}
}
}
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. Kattis - Fenwick Tree(树状数组区间更新单点求值)

    Fenwick Tree Input The first line of input contains two integers NN, QQ, where 1≤N≤50000001≤N≤500000 ...

  3. 【poj2155】Matrix(二维树状数组区间更新+单点查询)

    Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...

  4. HDU 3333 Turing Tree 离线 线段树/树状数组 区间求和单点修改

    题意: 给一个数列,一些询问,问你$[l,r]$之间不同的数字之和 题解: 11年多校的题,现在属于"人尽皆知傻逼题" 核心思想在于: 对于一个询问$[x,R]$ 无论$x$是什么 ...

  5. HDU 4031 Attack(线段树/树状数组区间更新单点查询+暴力)

    Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Sub ...

  6. 【树状数组区间修改单点查询】HDU 4031 Attack

    http://acm.hdu.edu.cn/showproblem.php?pid=4031 [题意] 有一个长为n的长城,进行q次操作,d为防护罩的冷却时间,Attack表示区间a-b的墙将在1秒后 ...

  7. 【树状数组区间修改单点查询+分组】HDU 4267 A Simple Problem with Integers

    http://acm.hdu.edu.cn/showproblem.php?pid=4267 [思路] 树状数组的区间修改:在区间[a, b]内更新+x就在a的位置+x. 然后在b+1的位置-x 树状 ...

  8. POJ 2155 Matrix(二维树状数组+区间更新单点求和)

    题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...

  9. NBOJv2 1050 Just Go(线段树/树状数组区间更新单点查询)

    Problem 1050: Just Go Time Limits:  3000 MS   Memory Limits:  65536 KB 64-bit interger IO format:  % ...

随机推荐

  1. template or render function not defined.

    template or render function not defined. H_婷 关注 2018.08.16 17:22 字数 106 阅读 3859评论 0喜欢 2 下午写 Vue $par ...

  2. Vue的模板语法

    基本语法 <body> <script src="vue.js"></script> <div id="app"> ...

  3. webgl推荐书籍

    网址:https://www.douban.com/doulist/45940373/ webgl 来自: Pasu2017-04-17创建   2017-07-25更新   推荐 关注 2 人关注 ...

  4. iOS工具】rvm、Ruby环境和CocoaPods安装使用及相关报错问题解决

    〇.前言 <p>在iOS开发中 CocoaPods作为库依赖管理工具就是一把利器. 有了 CocoaPods则无需再通过拖 第三方库及第三方库所依赖的 framework静态库到项目中等麻 ...

  5. CentOS7 export命令

    一.windows下的环境变量 在windows系统下,很多软件安装都需要配置环境变量,比如安装jdk,假如你没有配置环境变量,那么在非软件安装的目录下使用javac命令,系统将会报这不是系统内部命令 ...

  6. [Python3网络爬虫开发实战] 1.2.5-PhantomJS的安装

    PhantomJS是一个无界面的.可脚本编程的WebKit浏览器引擎,它原生支持多种Web标准:DOM操作.CSS选择器.JSON.Canvas以及SVG. Selenium支持PhantomJS,这 ...

  7. navicat连接mysql8报错,错误提示为1251,原因及解决步骤

    一.错误原因: MySQL8.0版本的加密方式和MySQL5.0的不一样,连接会报错. 二.解决步骤: 1.在linux虚拟机上登录mysql 2.更改加密方式: ALTER USER 'root'@ ...

  8. python 库文件版本收集及安装

    版本收集:pip freeze > require.txt版本安装:pip install -r require.txt

  9. iPhone安装ipa的方法(iTunes,PP助手)

    1,通过iTunes: 将手机与电脑通过数据线连接,打开电脑中的iTunes,将ipa文件添加到资料库(ipa文件是iTunes能够识别的文件),方式如下图,然后安装,同步即可. 2,通过PP助手: ...

  10. Excel表格如何设置密码 Excel2003/2007/2010设置密码教程

    http://www.wordlm.com/special/2/ 经常使用Excel表格制作报表和一些数据后,我们会给Excel表格设置密码,这样可以很有效的防止数据被盗取.目前Office版本众多, ...