http://acm.hdu.edu.cn/showproblem.php?pid=3584

C++版本一

树状数组

参考文章:http://blog.sina.com.cn/s/blog_5f5353cc0100kvmk.html

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
int ans,cnt,flag,temp;
bool a[N][N][N];
char str[2];
int x,y,z,x2,y2,z2;
int lowbit(int x){
    return x&(-x);
}
void updata(int x,int y,int z){
    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))
                a[i][j][k]^=1;
}
int sum(int x,int y,int z){
    int ans = 0 ;
    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))
                ans=(ans+a[i][j][k])&1;
    return ans;
}
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    while(~scanf("%d%d",&n,&m)){
        memset(a,0,sizeof(a));
        while(m--){
            scanf("%d",&q);
            if(q==0){
                scanf("%d%d%d",&x,&y,&z);
                cout<<sum(x+1,y+1,z+1)<<endl;
            }else{
                scanf("%d%d%d%d%d%d",&x,&y,&z,&x2,&y2,&z2);
                if(x>x2)swap(x,x2);
                if(y>y2)swap(y,y2);
                if(z>z2)swap(z,z2);
                updata(x,y,z);
                updata(x2+1,y2+1,z2+1);
                updata(x2+1,y,z);
                updata(x,y2+1,z);
                updata(x,y,z2+1);
                updata(x2+1,y2+1,z);
                updata(x,y2+1,z2+1);
                updata(x2+1,y,z2+1);
            }
        }
    }
    //cout << "Hello world!" << endl;
    return 0;
}