HDU 3584-Cube(三维BIT)

题意:

给你三维空间两种操作,给出两顶点坐标,把它们确定范围(长方体)内的数全部取反、查询给定点的值。初始全部为零

分析:

有了前面的知识,用BIT实现区间更新单点查询,再用多维实现即可

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
#define N 110
const ll  INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod =  1000000007;
int a[N][N][N],n,m;
int lowbit(int x){
    return x&(-x);
}
void add(int x,int y,int z){
    for(int i=x;i<=n;i+=lowbit(i))
        for(int j=y;j<=n;j+=lowbit(j))
        for(int k=z;k<=n;k=k+lowbit(k))
        a[i][j][k]++;//统计奇偶性+1,-1一样
}
int sum(int x,int y,int z){
    int num=0;
    for(int i=x;i>0;i-=lowbit(i))
        for(int j=y;j>0;j-=lowbit(j))
        for(int k=z;k>0;k-=lowbit(k))
        num+=a[i][j][k];
    return num;
}
int main()
{
    int op,x1,y1,z1,x2,y2,z2;
    while(~scanf("%d%d",&n,&m)){
        memset(a,0,sizeof(a));
        while(m--){
        scanf("%d",&op);
        if(op==1){
            scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
            add(x1,y1,z1);
            add(x1,y1,z2+1);
            add(x2+1,y1,z1);
            add(x1,y2+1,z1);
            add(x2+1,y2+1,z1);
            add(x2+1,y1,z2+1);
            add(x1,y2+1,z2+1);
            add(x2+1,y2+1,z2+1);
        }
        else{
            scanf("%d%d%d",&x1,&y1,&z1);
            printf("%d\n",sum(x1,y1,z1)%2);
        }
      }
    }
return 0;
}
时间: 2024-10-01 04:19:43

HDU 3584-Cube(三维BIT)的相关文章

HDU - 3584 Cube (三维树状数组 + 区间改动 + 单点求值)

HDU - 3584 Cube Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status 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. I

HDU - 3584 Cube (三维树状数组 + 区间修改 + 单点求值)

HDU - 3584 Cube Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status 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. I

HDU 3584 Cube --三维树状数组

题意:给一个三维数组n*n*n,初始都为0,每次有两个操作: 1. 翻转(x1,y1,z1) -> (x2,y2,z2) 0. 查询A[x][y][z] (A为该数组) 解法:树状数组维护操作次数,一个数被操作偶数次则相当于没被操作. 每次更新时在8个位置更新: .相当于8个二进制数:000,001,010,011,100,101,110,111. (我是由二维推过来的) 其实不用有的为-1,直接1也行,因为反正会改变奇偶性. 代码: #include <iostream> #inclu

HDU 3584 Cube (三维 树状数组)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3584 Cube 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, 

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 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"

HDU 3584 Cube(三维树状数组)

Cube Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 1660    Accepted Submission(s): 865 Problem Description Given an N*N*N cube A, whose elements are either 0 or 1. A[i, j, k] means the numbe

HDU 3584 Cube 【 三维树状数组 】

题意:还是那篇论文里面讲到的,三维树状数组http://wenku.baidu.com/view/1e51750abb68a98271fefaa8画个立方体出来对照一下好想一点 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6 #include<vector> 7 #include<

HDU 3584 Cube(三位树状数组)

Cube Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 1949    Accepted Submission(s): 1013 Problem Description Given an N*N*N cube A, whose elements are either 0 or 1. A[i, j, k] means the numbe

hdu 3584 二进制0,1反转 三维树状数组 及三维树状数组模板

先贴自己类比二维树状数组写的三维树状数组模板: 开始的时候循环体内j=y,k=z,没写,以为自己思路错了,,,hehe..... 更高维的树状数组以此类比 const int MAXN = 100+10; int c[MAXN][MAXN][MAXN];int X,Y,Z; int N; inline int lowbit(int x){return x&(-x);} void update(int x, int y, int z, int v) { int i=x,j=y,k=z; while

HDU 1253 (简单三维广搜) 胜利大逃亡

奇葩!这么简单的广搜居然爆内存了,而且一直爆,一直爆,Orz 而且我也优化过了的啊,尼玛还是一直爆! 先把代码贴上睡觉去了,明天再来弄 1 //#define LOCAL 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <queue> 6 #include <cmath> 7 using namespace std; 8 9 struct Poin