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. Linux学习笔记(7)Linux常用命令之压缩解压命令

    (1)gzip gzip命令用于压缩文件,英文原意为GNU zip,所在路径/bin/gzip,其语法格式为: gzip [文件] 压缩后的文件格式为.gz. 例:将/etc目录下的services文 ...

  2. 自己yy的fulkson最大流算法

    #include <iostream> #include <cstdio> #include <vector> using namespace std; ; //m ...

  3. AndroidManifest.xml权限大全

    本文转  https://my.oschina.net/duwaiweb/blog/75935 问登记属性 android.permission.ACCESS_CHECKIN_PROPERTIES , ...

  4. 让一个div在不同的显示器中永远居中

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  5. hdu1114 完全背包

    题意:给出钱罐的重量,然后是每种钱的价值和重量,问钱罐里最少可能有多少钱. 完全背包. 代码: #include<iostream> #include<cstdio> #inc ...

  6. scau 8637 阶乘与因子 筛素数

    时间限制:500MS  内存限制:1000K提交次数:189 通过次数:46 题型: 编程题   语言: G++;GCC Description 游戏玩了很久总会厌的,连Lyd的蚂蚁都被放生了.... ...

  7. wpf,图片灰化处理

    private BitmapSource ToGray(BitmapSource source) { FormatConvertedBitmap re = new FormatConvertedBit ...

  8. 《Getting Started with Storm》译文 Homepage

    拿到这本书感觉还挺薄,所以当下就想赶紧读完,然后尝试着翻译下,并加上一些自己的理解,作学习交流之用,非盈利性质 这段时间在做一个  分布式的.支持大吞吐的.实时的日志系统 ,主要用到的开源方案有Kaf ...

  9. js jQuery笔记

    jQuery 1.几种获取子元素的方法及区别 children方法获得的仅仅是元素一下级的子元素,即:immediate children. find方法获得所有下级元素,即:descendants ...

  10. jqgrid在colModel中多次调用同一个字段值

    Debug: 代码1: { name : 'input', index : 'input', width : 100, align : "center", formatter : ...