HDU 3584 树状数组
Cube
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 1956 Accepted Submission(s): 1017
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].
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.
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
0
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 树状数组的更多相关文章
- hdu 4638 树状数组 区间内连续区间的个数(尽可能长)
Group Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- hdu 4777 树状数组+合数分解
Rabbit Kingdom Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 2852 (树状数组+无序第K小)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2852 题目大意:操作①:往盒子里放一个数.操作②:从盒子里扔掉一个数.操作③:查询盒子里大于a的第K小 ...
- HDU 4911 (树状数组+逆序数)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4911 题目大意:最多可以交换K次,就最小逆序对数 解题思路: 逆序数定理,当逆序对数大于0时,若ak ...
- hdu 5792(树状数组,容斥) World is Exploding
hdu 5792 要找的无非就是一个上升的仅有两个的序列和一个下降的仅有两个的序列,按照容斥的思想,肯定就是所有的上升的乘以所有的下降的,然后再减去重复的情况. 先用树状数组求出lx[i](在第 i ...
- HDU 1934 树状数组 也可以用线段树
http://acm.hdu.edu.cn/showproblem.php?pid=1394 或者是我自己挂的专题http://acm.hust.edu.cn/vjudge/contest/view. ...
- 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 ...
- 【模板】HDU 1541 树状数组
http://acm.hdu.edu.cn/showproblem.php?pid=1541 题意:给你一堆点,每个点右一个level,为其右下方所有点的数量之和,求各个level包含的点数. 题解: ...
- hdu 5147 树状数组
题意:求满足a<b<c<d,A[a]<A[b],A[c]<A[d]的所有四元组(a,b,c,d)的个数 看到逆序对顺序对之类的问题一开始想到了曾经用归并排序求逆序对,结果 ...
随机推荐
- ASP.NET MVC使用过滤器进行权限控制
1.新建MVC项目 2.找到Models文件夹,新建 LoginCheckFilterAttribute 类 public class LoginCheckFilterAttribute : Acti ...
- 一张图入门python
- strust.xml
使用strust2框架,实现跳转,请求对应路径 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTY ...
- Memcached集群代理软件magent安装小结
magent是一个memcached代理软件(memcached agent),又叫memagent. (magent is a simple but useful proxy program for ...
- JQ学习(一)
通过 jQuery,您可以选取(查询,query) HTML 元素,并对它们执行“操作”(actions). jQuery 语法 jQuery 语法是为 HTML 元素的选取编制的,可以对元素执行某些 ...
- td 的colspan属性
看来要长长记性了,这个问题上次遇到过这次又犯了这个错. <table> <tr> <td colspan="10"> </td> & ...
- js的一些小笔记,(不定期更新)
2个$的用法$本身并无特定意义,它表示什么意思要看是如何定义的,如果没有定义就便是两个$,可能是变量名的开始.一般是一个函数,用来代替document.getElementByIdfunction $ ...
- 编解码-protobuf
Google的Protobuf在业界非常流行,很多商业项目选择Protobuf作为编解码框架,Protobuf的优点. (1)在谷歌内部长期使用,产品成熟度高: (2)跨语言,支持多种语言,包括C++ ...
- Python入门之树莓派
Linux命令行$+命令 pwd显示当前目录 ls列表 cd改变当前目录,/ sudo超级用户输入,特权来操作系统相关设置或删除文件 sudo apt-get install 安装程序 sudo ...
- 模数转换(A/D)和数模转换(D/A) 图示
(从书中截图) 在时间域和频率域中示意图: 1.A/D转换 2.D/A转换