CubeTime
limit:2000/1000 MS (java/others) Memory limit:131072/65536 K (java/others)
Total submission (s): 1660 Accepted Submission (s): 865
Problem Descriptiongiven an n*n*n cube A, whose elements is 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 operations, 1: ' Not ' operation that we change the A[i, J, k]=! A[i, J, K]. That's 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].
Inputmulti-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.
Outputfor each query output a[x, Y, z] on one line. (1<=n<=100 sum of M <=10000)
Sample Input
2 1 1 1 1 1 ten 1 1 each 1 1 1 2 2 20 1 1 10 2 2 2
Sample Output
101
Authoralpc32
Source2010 acm-icpc multi-university Training Contest (--host by Nudt)
Recommendzhouzeyong | We have carefully selected several similar problems for you:3450 1541 1892 2492 3743
Test instructionsA n*n*n cube with an element of 0 or 1 (initially 0). The 1 operation will reverse the element (X1,Y1,Z1) to (X2,Y2,Z2) and the 0 operation is a query (x, Y, z) of 0 or 1.
The three-dimensional tree-like array, the principle of one-dimensional, two-dimensional, can refer to http://blog.csdn.net/acm_baihuzi/article/details/46819049
#include <cstring> #include <algorithm> #include <iostream> #include <cstdlib> #include < Cstdio> #define N 110using namespace Std;int n,q;int bit[n][n][n];int getsum (int a,int b,int c) {int sum=0; for (int i=a, i>0; i-=i&-i) {for (Int. j=b; j>0; j-=j&-j) {for (int k=c; k>0; k-=k&-k ) {Sum+=bit[i][j][k]; }}} return sum;} void Add (int a,int b,int c) {for (Int. i=a; i<=n; i+=i&-i) {for (int j=b; j<=n; j+=j&-j) { for (int k=c; k<=n; k+=k&-k) {bit[i][j][k]^=1; }}}}int Main () {//freopen ("test.in", "R", stdin); while (cin>>n>>q) {memset (bit,0,sizeof bit); int op,x2,y2,z2,x1,y1,z1; while (q--) {scanf ("%d%d%d%d", &OP,&X1,&Y1,&Z1); if (op==0) {printf ("%d\n", Getsum (X1,Y1,Z1)%2); Continue } sCANF ("%d%d%d", &X2,&Y2,&Z2); Add (X1,Y1,Z1); Add (x1,y1,z2+1); Add (X1,Y2+1,Z1); Add (x1,y2+1,z2+1); Add (X2+1,Y1,Z1); Add (x2+1,y1,z2+1); Add (X2+1,Y2+1,Z1); Add (x2+1,y2+1,z2+1); }} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 3584 Cube (three-dimensional tree-like array)