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
 
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4.  
  5. using namespace std;
  6.  
  7. const int N=;
  8.  
  9. int n,m,arr[N][N][N];
  10.  
  11. int lowbit(int x){
  12. return x&(-x);
  13. }
  14.  
  15. void update(int i,int j,int k,int val){
  16. while(i<=n){
  17. int tmpj=j;
  18. while(tmpj<=n){
  19. int tmpk=k;
  20. while(tmpk<=n){
  21. arr[i][tmpj][tmpk]+=val;
  22. tmpk+=lowbit(tmpk);
  23. }
  24. tmpj+=lowbit(tmpj);
  25. }
  26. i+=lowbit(i);
  27. }
  28. }
  29.  
  30. int Sum(int i,int j,int k){
  31. int ans=;
  32. while(i>){
  33. int tmpj=j;
  34. while(tmpj>){
  35. int tmpk=k;
  36. while(tmpk>){
  37. ans+=arr[i][tmpj][tmpk];
  38. tmpk-=lowbit(tmpk);
  39. }
  40. tmpj-=lowbit(tmpj);
  41. }
  42. i-=lowbit(i);
  43. }
  44. return ans;
  45. }
  46.  
  47. int main(){
  48.  
  49. //freopen("input.txt","r",stdin);
  50.  
  51. while(~scanf("%d%d",&n,&m)){
  52. memset(arr,,sizeof(arr));
  53. int x1,y1,z1,x2,y2,z2;
  54. int op;
  55. while(m--){
  56. scanf("%d",&op);
  57. if(op==){
  58. scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
  59. update(x2+, y2+, z2+, );
  60. update(x1, y2+, z2+, );
  61. update(x2+, y1, z2+, );
  62. update(x2+, y2+, z1, );
  63. update(x1, y1, z2+, );
  64. update(x2+, y1, z1, );
  65. update(x1, y2+, z1, );
  66. update(x1, y1, z1, );
  67. }else {
  68. scanf("%d%d%d",&x1,&y1,&z1);
  69. printf("%d\n",Sum(x1,y1,z1)&); //该点的值就是sum(x,y)
  70. }
  71. }
  72. }
  73. return ;
  74. }

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. Kafka:ZK+Kafka+Spark Streaming集群环境搭建(二十四)Structured Streaming:Encoder

    一般情况下我们在使用Dataset<Row>进行groupByKey时,你会发现这个方法最后一个参数需要一个encoder,那么这些encoder如何定义呢? 一般数据类型 static ...

  2. [Algorithm] Reservoir Sampling

    Given a stream of elements too large to store in memory, pick a random element from the stream with ...

  3. 使用CSS3生成的电子时钟特效

    在线演示 本地下载 突然觉得自己对带工作的态度亟需改正,虽然不喜欢现在的加班生活,但是自己要去接受自己不喜欢的,才能获得自己喜欢的. 这是自己好久之前丛过的一个时钟,网上应该有这个的教程,虽然实现的效 ...

  4. Office办公 WPS如何设置页边距

    打开页眉页脚,在选项里面可以设置顶部的一行文字距离边界的距离   此外在页面布局,页边距也可以查看和修改                        

  5. IO multiplexing 与 非阻塞网络编程

    使用I/O multipexing 的网络编程中,一般需要采用非阻塞网络编程的风格,防止服务端在处理高连接量大时候阻塞在某个文件描述符上面,比如某个socket 有大量的数据需要写,但是内核发送缓冲区 ...

  6. Qt,Qt/E,Qtopia Core, Qtopia之间的区别和联系

    转自:http://www.qtcn.org/bbs/read.php?tid=10373 关于Qt,Qt/E,Qtopia Core, Qtopia这些版本之间的区别和联系: Qt泛指Qt的所有桌面 ...

  7. Android开之在非UI线程中更新UI

    当在非UI线程中更新UI(程序界面)时会出现例如以下图所看到的的异常: 那怎样才干在非UI线程中更细UI呢? 方法有非常多种.在这里主要介绍三种: 第一种:调用主线程mHandler的post(Run ...

  8. 一个简单的 JSON 生成/解析库

    这是一个单文件的,适用于C语言的, JSON 读写库. 先说明,不想造轮子,代码是从这里拿来的: https://www.codeproject.com/Articles/887604/jWrite- ...

  9. C#实现发布订阅模式

    首先给出项目的结构 IPublish.cs的源码: namespace NsWebChat.PublishSubscribe { /// <summary> /// 发布事件基础接口 // ...

  10. V-rep学习笔记:串口操作

    VREP Regular API提供了串口操作的相关函数,可以对串口进行打开.关闭和读写: 下面使用一款淘宝上常见的AHRS(Attitude and heading reference system ...