HDU-3584-Cube

原文鏈接:https://www.cnblogs.com/clnchanpin/p/7135784.html

膜拜: https://www.cnblogs.com/clnchanpin/p/7135784.html

                                                     Cube

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

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

2010 ACM-ICPC Multi-University Training Contest(15)——Host by NUDT

Recommend

zhouzeyong   |   We have carefully selected several similar problems for you:  3450 1892 3743 2852 2227  

題意 :大家都應該明白,就是一個三維的樹狀數組。但是,我操了,這個邊界值,思維不好我估計咱們的腦殼就炸了。

我也沒辦法畫出來,但是我做完想到了一個方法,三維,六個面,那麼把六個面都畫出來,取邊界值就ok了。

前、後、左、右、上、下(當然如果思維能力很強就無所謂了)

實在不行就找個A4紙,畫一個大一點的正方體,取兩個點,畫一畫就出來了。

反正算法沒啥難的嗎,就是這個邊界。。。。。

如果想到什麼方法還會更新《未完待續。。。》期待大佬有好的方法清晰地找出。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<algorithm>
#define sc(x) scanf("%d",&x)
#define scc(x,y) scanf("%d%d",&x,&y)
#define scll(x) scanf("%lld",&x)
#define mem(x) memset(x,0,sizeof x)
#define ll long long

using namespace std;

const int maxn = 105;
int c[maxn][maxn][maxn];
int N,M;

int lowbit(int x){
    return x & -x;
}

void update(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+=lowbit(k)){
                c[i][j][k]+=1;
            }
        }
    }
}

int query(int x,int y,int z){
    int total=0;
    for(int i=x;i;i-=lowbit(i)){
        for(int j=y;j;j-=lowbit(j)){
            for(int k=z;k;k-=lowbit(k)){
                total+=c[i][j][k];
            }
        }
    }
    return total & 1;
}

int main(){
    while(scc(N,M)!=EOF){
        mem(c);
        for(int i=1;i<=M;i++){
            int op;
            sc(op);
            if(op==1){
                int x1,y1,z1,x2,y2,z2;
                scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
                update(x2+1,y2+1,z2+1);
                update(x2+1,y2+1,z1);
                update(x2+1,y1,z2+1);
                update(x1,y2+1,z2+1);
                update(x1,y1,z2+1);
                update(x1,y2+1,z1);
                update(x2+1,y1,z1);
                update(x1,y1,z1);
            }
            if(op==0){
                int x1,y1,z1;
                scanf("%d%d%d",&x1,&y1,&z1);
                cout<<query(x1,y1,z1)<<endl;
            }
        }
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章