Source: Ural 1470. UFOs
Question: Calculate the three-dimensional interval and
Ideas:
# Include <cstdio> # include <cstring> using namespace STD; const int maxn = 130; int A [maxn] [maxn] [maxn]; int B [maxn] [maxn] [maxn]; int N, Q; int lowbit (INT X) {return X &-X;} void Update (INT X, int y, int Z, int num) {for (INT I = x; I <= N; I + = lowbit (I) for (Int J = y; j <= N; J + = lowbit (j) for (INT k = z; k <= N; k + = lowbit (k )) {A [I] [J] [k] + = num ;}} int sum (INT X, int y, int Z) {int ans = 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) {ans + = A [I] [J] [k];} return ans;} int main () {scanf ("% d", & N); While (scanf ("% d", & Q) & Q! = 3) {If (q = 1) {int X, Y, Z, K; scanf ("% d", & X, & Y, & Z, & K); X ++, y ++, Z ++; If (B [x] [y] [Z] + k> = 0) {Update (X, Y, Z, k); B [x] [y] [Z] + = K;} else {Update (X, Y, Z, B [x] [y] [Z]); B [x] [y] [Z] = 0 ;}} else if (q = 2) {int X1, y1, Z1, X2, Y2, Z2; scanf ("% d", & X1, & Y1, & Z1, & X2, & Y2, & Z2); X1 ++, Y1 ++, Z1 ++, X2 ++, Y2 ++, Z2 ++; int ans = sum (X2, Y2, z2)-sum (x1-1, Y2, Z2)-sum (X2, y1-1, Z2) + sum (x1-1, y1-1, Z2)-(sum (X2, Y2, z1-1) -sum (x1-1, Y2, z1-1)-sum (X2, y1-1, z1-1) + sum (x1-1, y1-1, z1-1); printf ("% d \ n ", ans) ;}} return 0 ;}