Cube

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

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
题意:三维坐标内,每一个点初始值为0,每次改变1->0,0->1,1 111 222,表示改变(1,1,1)~(2,2,2)范围的点,0 111 表示(1,1,1)点的值几。
代码:
  1. /*
  2. 这题挺巧妙,树状数组求和,因为变1次和变三次一样所以最后变得次数是奇数结果就是1,偶数结果就是0;
  3. 变数的时候注意是三维的,要改变8个顶点的值才能保证求和正确。
  4. */
  5. #include<iostream>
  6. #include<cstdio>
  7. #include<cstring>
  8. using namespace std;
  9. int A[][][];
  10. int n,m;
  11. int lowbit(int a)
  12. {
  13. return a&(-a);
  14. }
  15. void change(int a1,int b1,int c1)
  16. {
  17. for(int i=a1;i<=n;i+=lowbit(i))
  18. {
  19. for(int j=b1;j<=n;j+=lowbit(j))
  20. {
  21. for(int k=c1;k<=n;k+=lowbit(k))
  22. {
  23. A[i][j][k]++;
  24. }
  25. }
  26. }
  27. }
  28. int sum(int a1,int b1,int c1)
  29. {
  30. int ans=;
  31. for(int i=a1;i>;i-=lowbit(i))
  32. {
  33. for(int j=b1;j>;j-=lowbit(j))
  34. {
  35. for(int k=c1;k>;k-=lowbit(k))
  36. {
  37. ans+=A[i][j][k];
  38. }
  39. }
  40. }
  41. return ans&;
  42. }
  43. int main()
  44. {
  45. int x,x1,y1,z1,x2,y2,z2;
  46. while(scanf("%d%d",&n,&m)!=EOF)
  47. {
  48. memset(A,,sizeof(A));
  49. while(m--)
  50. {
  51. scanf("%d",&x);
  52. if(x)
  53. {
  54. scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
  55. change(x1,y1,z1);
  56. change(x2+,y2+,z2+);
  57. change(x2+,y1,z1);
  58. change(x1,y2+,z1);
  59. change(x1,y1,z2+);
  60. change(x1,y2+,z2+);
  61. change(x2+,y1,z2+);
  62. change(x2+,y2+,z1);
  63. }
  64. else
  65. {
  66. scanf("%d%d%d",&x1,&y1,&z1);
  67. printf("%d\n",sum(x1,y1,z1));
  68. }
  69. }
  70. }
  71. return ;
  72. }
 

HDU 3584 树状数组的更多相关文章

  1. hdu 4638 树状数组 区间内连续区间的个数(尽可能长)

    Group Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  2. hdu 4777 树状数组+合数分解

    Rabbit Kingdom Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  3. HDU 2852 (树状数组+无序第K小)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2852 题目大意:操作①:往盒子里放一个数.操作②:从盒子里扔掉一个数.操作③:查询盒子里大于a的第K小 ...

  4. HDU 4911 (树状数组+逆序数)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4911 题目大意:最多可以交换K次,就最小逆序对数 解题思路: 逆序数定理,当逆序对数大于0时,若ak ...

  5. hdu 5792(树状数组,容斥) World is Exploding

    hdu 5792 要找的无非就是一个上升的仅有两个的序列和一个下降的仅有两个的序列,按照容斥的思想,肯定就是所有的上升的乘以所有的下降的,然后再减去重复的情况. 先用树状数组求出lx[i](在第 i ...

  6. HDU 1934 树状数组 也可以用线段树

    http://acm.hdu.edu.cn/showproblem.php?pid=1394 或者是我自己挂的专题http://acm.hust.edu.cn/vjudge/contest/view. ...

  7. 2018 CCPC网络赛 1010 hdu 6447 ( 树状数组优化dp)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6447 思路:很容易推得dp转移公式:dp[i][j] = max(dp[i][j-1],dp[i-1][j ...

  8. 【模板】HDU 1541 树状数组

    http://acm.hdu.edu.cn/showproblem.php?pid=1541 题意:给你一堆点,每个点右一个level,为其右下方所有点的数量之和,求各个level包含的点数. 题解: ...

  9. hdu 5147 树状数组

    题意:求满足a<b<c<d,A[a]<A[b],A[c]<A[d]的所有四元组(a,b,c,d)的个数 看到逆序对顺序对之类的问题一开始想到了曾经用归并排序求逆序对,结果 ...

随机推荐

  1. Hbase原理、基本概念、基本架构

    来源:http://blog.csdn.net/woshiwanxin102213/article/details/17584043 概述 HBase是一个构建在HDFS上的分布式列存储系统:HBas ...

  2. loadrunner参数化excel数据

    LR参数化数据源Oracle,MSSQL,Excel参数化的方法: 重点介绍excel数据参数化的方法: 1.首先创建excel表格: 注意要写列明   2.创建excel表连接:   参数化完成后, ...

  3. 30分钟LINQ教程(转)

    在说LINQ之前必须先说说几个重要的C#语言特性 一:与LINQ有关的语言特性 1.隐式类型 (1)源起 在隐式类型出现之前, 我们在声明一个变量的时候, 总是要为一个变量指定他的类型 甚至在fore ...

  4. 《DSP using MATLAB》示例Example4.7

    ROC分三种情况:

  5. js-原型以及继承小案例

    function human(name,tall){ this.name=name; this.tall=tall; this.toSleep=function(){ alert('no sleep' ...

  6. 字体和壁纸合并后再更改壁纸--《用delphi开发共享软件》-15.2桌面提示器

    procedure TFrmPlay.mnDeskPicClick(Sender: TObject); Var s:String; i:Integer; begin //s:=Path+'SetPic ...

  7. 差分约束系统 POJ 3169 Layout

    题目传送门 题意:有两种关系,n牛按照序号排列,A1到B1的距离不超过C1, A2到B2的距离不小于C2,问1到n的距离最大是多少.如果无限的话是-2, 如果无解是-1 分析:第一种可以写这样的方程: ...

  8. 疯狂java学习笔记之面向对象(三) - 方法所属性和值传递

    方法的所属性: 从语法的角度来看:方法必须定义在类中 方法要么属于类本身(static修饰),要么属于实例 -- 到底是属于类还是属于对象? 有无static修饰 调用方法时:必须有主调对象(主语,调 ...

  9. static方法中为什么使用的都是静态变量

    static方法中需要使用静态变量.假设其他类要使用该方法,该方法里面所使用的变量是非静态的,如果该方法所在的类没有实例化,会导致该方法里面的变量不能实例化,自然该static 方法不能使用

  10. 每天一个linux命令--more/less

    最近小编在和第三方调试接口,只能查日志,查询除了tail,grep,cat,之外,还有 more.less,他们的优点在于可以翻页. more最基本的指令就是按空白键(space)就往下一页显示,按  ...