Cube
Time Limit: 2000/1000 MS (Java/others) memory limit: 131072/65536 K (Java/Others)
Total submission (s): 48 accepted submission (s): 32
Problem descriptiongiven an 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 [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].
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] in one line. (1 <= n <= 100 sum of M <= 10000)
Sample Input
2 51 1 1 1 1 1 10 1 1 11 1 1 1 2 2 20 1 1 10 2 2 2
Sample output
101
Authoralpc32
Source2010 ACM-ICPC multi-university training Contest (15) -- host by nudt question a lot at the beginning of TLE, there is no way to understand the report that the use of tree array to solve, so I learned the next tree array. It is really elegant # include <iostream> using namespace STD; const int n = 102; int C [N] [N] [N]; int lowbit (INT t) {return T & (-T);} void trans (INT Div, int X, int y) {int t; while (x> 0) {T = y; while (T> 0) {C [Div] [x] [T] = 1-C [Div] [x] [T]; t-= lowbit (t);} X-= lowbit (x);} int plus (INT Div, int X, int y) {int T, sum = 0; while (x <n) {T = y ; While (T <n) {sum = (sum + C [Div] [x] [T]) & 1; t + = lowbit (t );} X + = lowbit (x);} return sum;} int main () {int n, m, I, j, x1, x2, Y1, Y2, Z1, Z2; while (scanf ("% d", & N, & M )! = EOF) {int flag; int S, E; memset (C, 0, sizeof (c); While (M --) {scanf ("% d ", & flag); If (FLAG) {scanf ("% d", & X1, & Y1, & Z1 ); scanf ("% d", & X2, & Y2, & Z2); for (I = Z1; I <= Z2; I ++) {TRANS (I, X2, Y2); Trans (I, X2, y1-1); Trans (I, x1-1, Y2); Trans (I, x1-1, y1-1 );}} else {scanf ("% d", & X1, & Y1, & Z1); printf ("% d/N", plus (Z1, X1, y1) ;}} return 0 ;}