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. VS2015 update3 安装 asp.net core 失败

    CMD 命令下执行: C:\DotNetCore\DotNetCore.1.0.0-VS2015Tools.Preview2.exe SKIP_VSU_CHECK=1

  2. java web 学习笔记 - servlet01

    ---恢复内容开始--- 1.Servlet介绍 Servlet 是用java语言编写的服务器端小程序,属于一个CGI程序,但与传统的CGI不同的是,它是多线程实现的,并且可以多平台移植. 用户自定义 ...

  3. fedora下yum安装gnome和kde桌面 (有问题 )

    转自:   http://linux.chinaunix.net/techdoc/system/2009/08/31/1133198.shtml 1.1  安装KDE桌面环境 yum groupins ...

  4. C# 如何发送Http请求

    HttpSender是一个用于发送Http消息的轻量C#库,使用非常简单,只需要一两行代码,就能完成Http请求的发送 使用 Nuget,搜索 HttpSender 就能找到这个库 这个库的命名空间是 ...

  5. vue工程化:返回顶部和底部的动画效果

    . <template> <div> <div class="scroll" :class="{show:isActive}"&g ...

  6. java_String类练习

    public class StringTest { //1.模拟trim方法,去除字符串两端的空格 public static void main(String[] args) { String st ...

  7. live555简介

    live555 编辑   目录 1live555简介 2Live555 Streaming Media整体框架 3openRTSP客户端流程     1live555简介编辑 Live555 是一个为 ...

  8. 零基础入门学习Python(29)--文件:一个任务

    知识点 一个任务:将文件(record.txt)中的数据进行分割并按照以下规律保存起来: #record.txt文件内容: 小客服:小甲鱼,今天有客户问你有没有女朋友? 小甲鱼:咦?? 小客服:我跟她 ...

  9. UVA 140 Bandwidth (dfs 剪枝 映射)

    题意: 给定一个n个结点的图G和一个结点的排列, 定义结点i的带宽b(i)为i和相邻结点在排列中的最远距离, 所有b(i)的最大值就是这个图的带宽, 给定G, 求让带宽最小的结点排列. 给定的图 n ...

  10. 细说php第八章笔记(初稿)

    8.1 函数的定义      函数是被命名的:      函数是独立的:      函数执行特定的任务:      函数可以用将一个返回值返回给调用他的程序 函数的优越性      提高程序的重用性 ...