HDU-3584Cube
Time Limit: 1000MS |
|
Memory Limit: 65536KB |
|
64bit IO Format: %i64d &%i64u |
Submit Status Description Given 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].
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] (1<=n<=100 sum of M <=10000)Sample Input 2 1 1 1 1 1 10 1 1 11 1 1 1 Sample Output /*author:2486memory:5944 kbtime:202 MSLANGUAGE:G++RESULT:ACCEPTEDVJ runid:4328542real runid:14413386*///Three-dimensional and the same as two-dimensional, And the two-dimensional is the same as the one-dimensional//concrete explanation. This blog answers the principles of how to do this. # include <cstdio> #include <cstring> #include <algorithm> #include <vector># Include <queue>using namespace Std;const int maxn = + 5;int c[maxn][maxn][maxn];int 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 + = Lowbi T (j)) {for (int k = z; k <= N; k + = Lowbit (k)) {C[i][j][k] + +; }}}}int query (int x, int y, int z) {int ret = 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)) {ret + = C[i][j][k]; }}} return ret & 1;} int X, x, Y, Z, x1, y1, Z1, x2, Y2, z2;int main () {while (~ scanf ("%d%d", & N, &m)) {memset (c, 0, sizeof (c)); while (M-) {scanf ("%d", &x); if (X) {scanf ("%d%d%d%d%d%d", &x1, &y1, &z1, &x2, &y2, &Z2); X2 + +; y2 + +; Z2 + +; Add (x1, y1, Z1); Add (x1, y2, Z1); Add (x1, y1, Z2); Add (x1, y2, Z2); Add (x2, Y1, Z1); Add (x2, Y2, Z1); Add (x2, y1, Z2); Add (x2, y2, Z2); } else {scanf ("%d%d%d", &x, &y, &z); printf ("%d\n", query (x, Y, z)); }}} return 0;}
|