HDU 3584 Cube (three-dimensional tree-like array)

Source: Internet
Author: User

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&LT;=I&LT;=X2,Y1&LT;=J&LT;=Y2,Z1&LT;=K&LT;=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", &AMP;OP,&AMP;X1,&AMP;Y1,&AMP;Z1);                if (op==0) {printf ("%d\n", Getsum (X1,Y1,Z1)%2);            Continue } sCANF ("%d%d%d", &AMP;X2,&AMP;Y2,&AMP;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)

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.