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. (转)淘淘商城系列——zookeeper单机版安装

    http://blog.csdn.net/yerenyuan_pku/article/details/72717744 这篇文章,我单独来说一下zookeeper如何安装.在实际开发中,zookeep ...

  2. 对称加密DES加密

    DES加密: des是对称加密,加密和解密需要相同的秘钥,它的密码最长56位,必须是8的倍数,秘钥越长,越安全. package com.trm.util.encrypt; import java.s ...

  3. 在Gitlab上怎么添加ssh key

    原因分析: 某台centos没有权限克隆gitlab上的git项目,没有权限,报错信息如下 我首先想到的是,在gitlab上没有添加这台centos服务器的秘钥,导致没有权限拉取项目信息 解决步骤: ...

  4. WPF知识点--渐变色(LinearGradientBrush、GradientStop)

    [LinearGradientBrush-- 使用线性渐变绘制区域](https://msdn.microsoft.com/zh-cn/library/system.windows.media.lin ...

  5. 由于未清除缓存引发的bug

    在写页面的时候,首先引入了本地react.js和react-dom.js 16版本(cjs)的文件,出现如下错误 发现bug后,将本地的react.js和react-dom.js文件改成16.2(um ...

  6. C++运行外部exe并判断exe返回值

    有三个API函数可以运行可执行文件WinExec.ShellExecute和CreateProcess.CreateProcess因为使用复杂,比较少用. WinExec主要运行EXE文件. ⑴ 函数 ...

  7. bat copy

    @echo off regedit /s %~dp0regedit.reg                                          //注册注册表xcopy "D: ...

  8. oracle优化器使用(oracle11g)

    一:优化器介绍 优化器(optimizer)是oracle数据库内置的一个核心子系统.优化器的目的是按照一定的判断原则来得到它认为的目标SQL在当前的情形下的最高效的执行路径,也就是为了得到目标SQL ...

  9. javascript——js string 转 int 注意的问题——parseInt(转)

    <script>     var   str='1250' ;  alert( Number(str) );  //得到1250 alert(parseInt(str));  //得到12 ...

  10. iOS缓存到sandbox

        在手机应用程序开发中,为了减少与服务端的交互次数,加快用户的响应速度,一般都会在iOS设备中加一个缓存的机制,前面一篇文章介绍了iOS设备的内存缓存,这篇文章将设计一个本地缓存的机制. 功能需 ...