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. Google浏览器开发者工具:CSSViewer(一个Css查看器)

    CSSViewer的简介 CSSViewer是一款可以帮助用户快速查看当前的网页元素的CSS属性的谷歌浏览器插件,在Chrome中安装了CSSViewer插件以后,用户就可以在设计网页的时候,快速地模 ...

  2. sql中的日期时间处理

    每个数据库,不同的日期格式化: 1.mysql 2.sqlserver 使用Convert()函数: select convert(char(10),GetDate(),120) as Date 第3 ...

  3. Java方法注释模板

    普通方法 /** * ${todo} * @author: SYJP * @version 创建时间:${date} */ 覆盖方法 /** * @Title: ${enclosing_method} ...

  4. cal - 显示一个日历

    总览 cal [-mjy ] [月份 [年份 ] ] 描述 Cal 显示一个简单的日历.. 如果没有指定参数, 则显示当前月份. 选项如下所列: -m 显示星期一作为一周的第一天.. (缺省为星期日. ...

  5. autofs - automounter maps的格式

    描述(DESCRIPTION) automounter maps 是一系列非主映射文件或者是NIS映射(NIS maps),它们被 automounter 的主映射文件(master map)具体调用 ...

  6. CAD参数绘制椭圆弧(com接口)

    在CAD设计时,需要绘制椭圆弧,用户可以设置椭圆弧基本属性. 主要用到函数说明: _DMxDrawX::DrawEllipseArc 绘制椭圆弧.详细说明如下: 参数 说明 DOUBLE dCente ...

  7. mac 下安装python pil

    mac:sudo brew install freetype sudo pip install pillow ubuntu: sudo apt-get install libfreetype6-dev ...

  8. 无插件纯Web 3D机房,HTML5+WebGL倾力打造

    前言 最近项目开发任务告一段落,刚好有时间整理这大半年的一些成果.使用html5时间还不久,对js的认识还不够深入.没办法,以前一直搞java,对js的一些语言特性和概念一时还转换不过来. 上一篇大数 ...

  9. ajax中的json和jsonp详解

    出现的问题: 花了点时间研究ajax中的json和jsonp的原理,这里记录一下.以前一直在使用ajax调用数据,但是从来没有遇到跨域问题,也从来没有注意过json和jsonp的区别,总是一通乱用.但 ...

  10. LG-P1311选择客栈

    题目 暴力十分好想但你写不出来qwq 正解十分好写但你想不出来qaq 我们先读题,发现k其实没什么用 同时暴力枚举两个客栈的话会超时,所以只能同时枚举一个.我们枚举第二个客栈,然后用第二个客栈反推出前 ...