HDU-3584 Cube (three-dimensional tree array + interval change + single point evaluation)

Source: Internet
Author: User

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&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].

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, &AMP;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;}

HDU-3584 Cube (three-dimensional tree array + interval change + single point evaluation)

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.