Hdu3584 cube tree Array

Source: Internet
Author: User

 

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 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.