Topic Links:
http://acm.hdu.edu.cn/showproblem.php?pid=3584
Main topic:
Given an N*n*n Cube A, its elements are 0 or 1. A[i,j,k] represents the first
Row I, the value of column J and level K.
First by a[i,j,k] = 0 (1 <= i,j,k <= N).
Given two actions:
1: Change A[i,j,k] for! A[I,J,K].
2: The value of Query A[i,j,k].
Problem Solving Ideas:
Three-dimensional tree-like array simulation using the principle of tolerant repulsion
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5#include <string>6#include <cmath>7#include <Set>8#include <queue>9#include <map>Ten#include <stack> One#include <vector> A#include <list> -#include <deque> -#include <sstream> the#include <cctype> - #defineREP (i, n) for (int i = 0; I < (n); i++) - #defineFor (I, S, T) for (int i = (s); I < (t); i++) - #defineMEM (A, X) memset (A, X, sizeof (a)); + using namespacestd; -typedefLong Longll; +typedef unsignedLong Longull; A Const intMAXN = the; at Const DoubleEPS = 1e-Ten; - Const intINF =1<< -; - Const intdir[4][2] = {1,0,0,1,0,-1,-1,0}; - Const DoublePI =3.1415926535898; - intT, N, m, cases; - intTREE[MAXN][MAXN][MAXN]; in intA[MAXN][MAXN][MAXN]; - intLowbit (intx) to { + returnx& (-x); - } the intSumintXintYintz) * { $ intAns =0;Panax Notoginseng for(inti = x; I <= N; i + =lowbit (i)) - for(intj = y; J <= N; J + =Lowbit (j)) the for(intK = Z; K <= N; K + =Lowbit (k)) +Ans + =Tree[i][j][k]; A returnans; the } + voidAddintXintYintZintd) - { $ for(inti = x; i >0; I-=lowbit (i)) $ for(intj = y; J >0; J-=Lowbit (j)) - for(intK = Z; K >0; K-=Lowbit (k)) -Tree[i][j][k] + =D; the } - intMain ()Wuyi { the while(Cin >> N >>m) - { WuMEM (Tree,0); -MEM (A,0); About intT, x1, y1, Z1, x2, Y2, Z2; $ while(m--) - { -scanf"%d", &t); - if(t) A { +scanf"%d%d%d%d%d%d", &x1, &y1, &z1, &x2, &y2, &z2); theAdd (x2, y2, Z2,1); -Add (x2, y1-1, Z2,1); $Add (X1-1, Y2, Z2,1); theAdd (x2, y2, Z1-1,1); theAdd (X1-1, Y1-1, Z2,1); theAdd (X1-1, Y2, Z1-1,1); theAdd (x2, y1-1, Z1-1,1); -Add (X1-1, Y1-1, Z1-1,1); in } the Else the { Aboutscanf"%d%d%d", &x1, &y1, &z1); thecout<< (SUM (x1, y1, Z1) &1) <<Endl; the } the } + } - return 0; the}
hdu-3584 Cube---Three-dimensional tree array + area Update single point query