Click to open link
Test instructions: three-dimensional space has two operations, the initial time each space element is 0, and then the update operation is 0 to 0, is a space all elements are updated, and then query is asked whether the element of this point is 0 or 1
Idea: Because it is not good to update to each point, then we can count the number of space rollover, and then use three-dimensional tree array can be, but the update can not only update that point, because if so, can include this interval of the large interval because it has not been updated and become 1, that is not what we want, So we're going to surround the circle of this interval in an update, then the value is 2, without affecting the result
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #include < Algorithm>using namespace Std;typedef Long long ll;typedef unsigned long long ull;const int Inf=0x3f3f3f3f;const ll INF =0x3f3f3f3f3f3f3f3fll;const int maxn=110;int sum[maxn][maxn][maxn],n;int lowbit (int x) {return x& (-X);} void update (int x,int y,int z,int val) {for (Int. i=x;i<=n;i+=lowbit (i)) {for (int j=y;j<=n;j+=lowbit (j)) { for (int l=z;l<=n;l+=lowbit (l)) {sum[i][j][l]+=val; }}}}int msum (int x,int y,int z) {int res=0; For (Int. i=x;i>0;i-=lowbit (i)) {for (Int. j=y;j>0;j-=lowbit (J)) {for (int l=z;l>0;l-=lowbit (l)) { RES+=SUM[I][J][L]; }}} return res;} int main () {int m,x1,y1,z1,x2,y2,z2,type; while (scanf ("%d%d", &n,&m)!=-1) {memset (sum,0,sizeof (sum)); while (m--) {scanf ("%d", &type); if (TyPe==1) {scanf ("%d%d%d%d%d%d", &X1,&Y1,&Z1,&X2,&Y2,&Z2); Update (x1,y1,z1,1); update (x1,y1,z2+1,1); Update (x1,y2+1,z1,1); update (x1,y2+1,z2+1,1); Update (x2+1,y1,z1,1); update (x2+1,y1,z2+1,1); Update (x2+1,y2+1,z1,1); update (x2+1,y2+1,z2+1,1); }else{scanf ("%d%d%d", &X1,&Y1,&Z1); printf ("%d\n", Msum (X1,Y1,Z1) &1); }}} return 0;}
HDU 3584 tree-like array