HDU 3584 Cube (three-dimensional tree array), hdu3584
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
Three-dimensional tree array .. Add a for loop.
#include <iostream>#include <cstring>#include <cstdio>//#include <cmath>#include <set>#include <stack>#include <cctype>#include <algorithm>#define lson o<<1, l, m#define rson o<<1|1, m+1, rusing namespace std;typedef long long LL;const int mod = 99999997;const int MAX = 1000000000;const int maxn = 1005;int n, q, x1, y1, z1, x2, y2, z2, op;int c[101][101][101];void add(int x, int y, int z) { for(int i = x; i <= n; i += i&-i) for(int j = y; j <= n; j += j&-j) for(int k = z; k <= n; k += k&-k) c[i][j][k]++;}int query(int x, int y, int z) { int sum = 0; for(int i = x; i > 0; i -= i&-i) for(int j = y; j > 0; j -= j&-j) for(int k = z; k > 0; k -= k&-k) sum += c[i][j][k]; return sum;}int main(){ //freopen("in.txt", "r", stdin); while(cin >> n >> q) { memset(c, 0, sizeof(c)); while(q--) { scanf("%d%d%d%d", &op, &x1, &y1, &z1); if(op) { scanf("%d%d%d", &x2, &y2, &z2); x2++, y2++, z2++; add(x1, y1, z1); add(x1, y1, z2); add(x1, y2, z1); add(x2, y1, z1); add(x1, y2, z2); add(x2, y1, z2); add(x2, y2, z1); add(x2, y2, z2); } else printf("%d\n", query(x1, y1, z1) & 1); } } return 0;}
Zookeeper
HDU 3743 is just starting to look at the tree array. After reading it, you can only read some of the simplest questions.
Tree arrays are not mentioned here. They are learned by yourself. We recommend that you first make a water question. There are more than 10 typical questions in Baidu Library. For each question, it is required when you do not ask, but you only need to briefly ask your thoughts. If you ask every step in detail, the game will not be exploitable!