Cube

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 1166    Accepted Submission(s): 580

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
 
Author
alpc32
 
Source
 
Recommend
zhouzeyong
 
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int N=; int n,m,arr[N][N][N]; int lowbit(int x){
return x&(-x);
} void update(int i,int j,int k,int val){
while(i<=n){
int tmpj=j;
while(tmpj<=n){
int tmpk=k;
while(tmpk<=n){
arr[i][tmpj][tmpk]+=val;
tmpk+=lowbit(tmpk);
}
tmpj+=lowbit(tmpj);
}
i+=lowbit(i);
}
} int Sum(int i,int j,int k){
int ans=;
while(i>){
int tmpj=j;
while(tmpj>){
int tmpk=k;
while(tmpk>){
ans+=arr[i][tmpj][tmpk];
tmpk-=lowbit(tmpk);
}
tmpj-=lowbit(tmpj);
}
i-=lowbit(i);
}
return ans;
} int main(){ //freopen("input.txt","r",stdin); while(~scanf("%d%d",&n,&m)){
memset(arr,,sizeof(arr));
int x1,y1,z1,x2,y2,z2;
int op;
while(m--){
scanf("%d",&op);
if(op==){
scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
update(x2+, y2+, z2+, );
update(x1, y2+, z2+, );
update(x2+, y1, z2+, );
update(x2+, y2+, z1, );
update(x1, y1, z2+, );
update(x2+, y1, z1, );
update(x1, y2+, z1, );
update(x1, y1, z1, );
}else {
scanf("%d%d%d",&x1,&y1,&z1);
printf("%d\n",Sum(x1,y1,z1)&); //该点的值就是sum(x,y)
}
}
}
return ;
}

HDU 3584 Cube (三维数状数组)的更多相关文章

  1. HDU - 3584 Cube (三维树状数组 + 区间改动 + 单点求值)

    HDU - 3584 Cube Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Subm ...

  2. HDU 3584 Cube --三维树状数组

    题意:给一个三维数组n*n*n,初始都为0,每次有两个操作: 1. 翻转(x1,y1,z1) -> (x2,y2,z2) 0. 查询A[x][y][z] (A为该数组) 解法:树状数组维护操作次 ...

  3. HDU 1394Minimum Inversion Number 数状数组 逆序对数量和

    Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  4. HDU 3584 Cube (三维树状数组)

    Problem Description Given an N*N*N cube A, whose elements are either 0 or 1. A[i, j, k] means the nu ...

  5. HDU 3584 Cube 【 三维树状数组 】

    题意:还是那篇论文里面讲到的,三维树状数组http://wenku.baidu.com/view/1e51750abb68a98271fefaa8画个立方体出来对照一下好想一点 #include< ...

  6. HDU 3584 三维树状数组

    三维树状数组模版.优化不动了. #include <set> #include <map> #include <stack> #include <cmath& ...

  7. HDU 1166 敌兵布阵 (数状数组,或线段树)

    题意:... 析:可以直接用数状数组进行模拟,也可以用线段树. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000&quo ...

  8. 1470. UFOs(三维树状数组)

    1470 最简单的三维树状数组 #include <iostream> #include<cstdio> #include<cstring> #include< ...

  9. poj 2481 Cows(数状数组 或 线段树)

    题意:对于两个区间,[si,ei] 和 [sj,ej],若 si <= sj and ei >= ej and ei - si > ej - sj 则说明区间 [si,ei] 比 [ ...

随机推荐

  1. Java Web 生成临时文件并下载(原)

    概述:本文是  java 服务器端生成文件并下载的示例,并不完善,下载之后一般来说还需要删除临时文件. 注意:临时文件存放在 /WEB-INF/tmp 目录下,所以先要把  tmp 目录建起来. pu ...

  2. Linux:磁盘挂载

    本来虚拟centos的服务器的磁盘分配的就不大,之前只分配了20G的样子,由于最近有装了不少软件,比如nifi压缩版就有1.2G的大小,一下子没有磁盘资源了.今晚就折腾在这事上了. [root@mas ...

  3. 怎样在一个项目里用logger在控制台打印信息

    第一步: 导入jar包,maven项目可以直接添加 <dependency><groupId>log4j</groupId><artifactId>lo ...

  4. [Functional Programming] Create Reusable Functions with Partial Application in JavaScript

    This lesson teaches you how arguments passed to a curried function allow us to store data in closure ...

  5. C#.NET常见问题(FAQ)-如何修改Form不能修改窗体大小

    把FormBorderSytle改一下就可以了,改成FixedSingle或者Fixed3D都可以   更多教学视频和资料下载,欢迎关注以下信息: 我的优酷空间: http://i.youku.com ...

  6. 解决Android Studio提示gradle project sync failed报错的解决方法

    运行的时候报错,提示:gradle project sync failed 1.打开AS,切换到project目录结构依次进入目录app->gradle->gradle-wrapper.p ...

  7. Unity3D 学习 创建简单的按钮、相应事件

    选择file -->new project 然后保存到相应的地方 下面是这个刚创建的工程效果图. 然后创建一个C# Script ||定位到最左下角找到  assets --> creat ...

  8. vsphere性能

    vNUMA介绍 http://virtualbarker.com/ vSphere VMware Performance With every release of vSphere the overh ...

  9. C++ 第十二课 其它标准C函数

    abort() 停止程序执行 assert() 当表达式非真,停止程序执行 atexit() 当程序退出执行设定的程序 bsearch() 执行折半查找 exit() 停止程序执行 getenv() ...

  10. mysql 俩个时间相减后取分钟

    CASE WHEN TIMESTAMPDIFF(MINUTE,o.createDate,o.chargingStartDate) != THEN 'APP解锁计费' ELSE '系统自动计费' END ...