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次和变三次一样所以最后变得次数是奇数结果就是1,偶数结果就是0;
变数的时候注意是三维的,要改变8个顶点的值才能保证求和正确。
*/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int A[][][];
int n,m;
int lowbit(int a)
{
return a&(-a);
}
void change(int a1,int b1,int c1)
{
for(int i=a1;i<=n;i+=lowbit(i))
{
for(int j=b1;j<=n;j+=lowbit(j))
{
for(int k=c1;k<=n;k+=lowbit(k))
{
A[i][j][k]++;
}
}
}
}
int sum(int a1,int b1,int c1)
{
int ans=;
for(int i=a1;i>;i-=lowbit(i))
{
for(int j=b1;j>;j-=lowbit(j))
{
for(int k=c1;k>;k-=lowbit(k))
{
ans+=A[i][j][k];
}
}
}
return ans&;
}
int main()
{
int x,x1,y1,z1,x2,y2,z2;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(A,,sizeof(A));
while(m--)
{
scanf("%d",&x);
if(x)
{
scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
change(x1,y1,z1);
change(x2+,y2+,z2+);
change(x2+,y1,z1);
change(x1,y2+,z1);
change(x1,y1,z2+);
change(x1,y2+,z2+);
change(x2+,y1,z2+);
change(x2+,y2+,z1);
}
else
{
scanf("%d%d%d",&x1,&y1,&z1);
printf("%d\n",sum(x1,y1,z1));
}
}
}
return ;
}
 

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. LoadRunner检查点学习实例

    LoadRunner只会检测脚本中事务的执行状态,而实际的事务执行结果则需要通过检查点来完成. 例如一个登录事务,LR只关心事务本身的执行状态,也就是说哪怕实际操作密码错误产生登录失败的业务操作,其事 ...

  2. JSON详解以及可以把javabean转换成json串的json-lib应用

    JSON 1. json是什么 它是js提供的一种数据交换格式! 2. json的语法 {}:是对象! 属性名必须使用双引号括起来!单引不行!!! 属性值:null,数值,字符串,数组:使用[]括起来 ...

  3. file-max与ulimit的关系与差别

    典型的,提供大量静态文件访问的web服务器,缓存服务器(如squid), 均要注意这个问题 网上的教程,大约只是简单说明了如何设置ulimit和file-max, 但并没有说清楚这两者之间的差别,让人 ...

  4. Liferay 6.2 改造系列之二十一:修改WebSphare下JSONWS服务不生效的BUG

    问题原因是WebSphare下,servletContext.getContextPath()获取到的值为“/”而非空字符串. 在/portal-master/portal-impl/src/com/ ...

  5. c#写windows服务(转)

    序言 前段时间做一个数据迁移项目,刚开始用B/S架构做的项目,但B/S要寄存在IIs中,而IIs又不稳定因素,如果重启IIs就要打开页面才能运行项目.有不便之处,就改用Windows服务实现.这篇就总 ...

  6. 阻止Ajax多次提交

    1.Ajax的abort() xhr = $.ajax({}) if (xhr){ xhr.abort(); } 2.通过在Ajax的beforeSend()方法以及complete()方法添加删除类 ...

  7. Linux 环境中普通用户启动Myeclipse出错

    将Myeclipse安装在/usr/local/myeclipse目录中,由root用户启动时没有问题,而用普通用户时出现如下故障: The configuration area at '/usr/l ...

  8. HDU4971 A simple brute force problem.(强连通分量缩点 + 最大权闭合子图)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=4971 Description There's a company with several ...

  9. React组件

    React组件 组件是React中的基本单位,在每个组件里面又封装了程序逻辑,通过reader标出界面片段或者回传一段描述,组件再通过React.renderComponent将组件展示在浏览器中.每 ...

  10. ScriptManager和ClientScript的区别

    ClientScript获取用于管理脚本.注册脚本和向页面添加脚本的ClientScriptManager对象. ScriptManager.RegisterStartupScript方法和Clien ...