Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int tree[150][150][150];
  6.  
  7. void inc(int n, int x, int y, int z, int d) {
  8.     for (int i = x; i < n; i = i | (i + 1)) {
  9.         for (int j = y; j < n; j = j | (j + 1)) {
  10.             for (int k = z; k < n; k = k | (k + 1)) {
  11.                 tree[i][j][k] += d;
  12.             }
  13.         }
  14.     }
  15. }
  16.  
  17. int sum(int x, int y, int z) {
  18.     int res = 0;
  19.     for (int i = x; i >= 0; i = (i & (i + 1)) - 1) {
  20.         for (int j = y; j >= 0; j = (j & (j + 1)) - 1) {
  21.             for (int k = z; k >= 0; k = (k & (k + 1)) - 1) {
  22.                 res += tree[i][j][k];
  23.             }
  24.         }
  25.     }
  26.     return res;
  27. }
  28.  
  29. int main() {
  30.     int n, cmd = -1;
  31.     cin >> n;
  32.     for (int i = 0; i < n; i++) {
  33.         for (int j = 0; j < n; j++) {
  34.             for (int k = 0; k < n; k++) {
  35.                 tree[i][j][k] = 0;
  36.             }
  37.         }
  38.     }
  39.     while (cmd != 3) {
  40.         cin >> cmd;
  41.         if (cmd == 1) {
  42.             int x, y, z, d;
  43.             cin >> x >> y >> z >> d;
  44.             inc(n, x, y, z, d);
  45.         }
  46.         if (cmd == 2) {
  47.             int x1, y1, z1, x2, y2, z2;
  48.             cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
  49.             int res = sum(x2, y2, z2) - sum(x2, y2, z1 - 1) - sum(x1 - 1, y2, z2) + sum(x1 - 1, y1 - 1, z2) -
  50.                       sum(x2, y1 - 1, z2) + sum(x1 - 1, y1 - 1, z2) + sum(x2, y1 - 1, z1 - 1) -
  51.                       sum(x1 - 1, y1 - 1, z1 - 1);
  52.             cout << res << '\n';
  53.         }
  54.     }
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement