首页 > 代码库 > HDU3584 Cube

HDU3584 Cube

题解:

三维IUPQ裸题,

画图分析一下就行了

代码:

#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<map>#include<set>using namespace std;#define pb push_back#define mp make_pair#define se second#define fs first#define LL long long#define CLR(x) memset(x,0,sizeof x)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1 typedef pair<int,int> P;const double eps=1e-9;const int maxn=20100;const int N=110;const int mod=1e9+7;const int INF=1e9;int a[N][N][N];int lowbit(int x){return x&-x;}void add(int x,int y,int z,int v){   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))   a[i][j][k]+=v;}int sum(int x,int y,int z){    int cnt=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))    cnt+=a[i][j][k];    return cnt;}int main(){    int n,m;    while(~scanf("%d%d",&n,&m)){    CLR(a);    for(int i=1;i<=m;i++){        int op;        scanf("%d",&op);        int x1,y1,z1,x2,y2,z2;        if(op==1){            scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);            add(x1,y1,z1,1);            add(x1,y1,z2+1,-1);            add(x1,y2+1,z1,-1);            add(x2+1,y1,z1,-1);            add(x2+1,y2+1,z2+1,-1);            add(x2+1,y2+1,z1,1);            add(x2+1,y1,z2+1,1);            add(x1,y2+1,z2+1,1);        }        if(op==0){            scanf("%d%d%d",&x1,&y1,&z1);            int ans=sum(x1,y1,z1);            //cout<<ans<<endl;            printf("%d\n",ans&1);        }    }   }    return 0;}

 

HDU3584 Cube