Advertisement
double_trouble

Fenwik

Mar 25th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. //#define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <vector>
  5. #include <cmath>
  6. #include <string>
  7. #include <algorithm>
  8. #include <string>
  9. #include <deque>
  10. #include <iomanip>
  11. #include <cstddef>
  12. #include <queue>
  13. #include <set>
  14.  
  15.  
  16. using namespace std;
  17.  
  18. int n;
  19. int tree[200][200][200];
  20. int a[33000];
  21.  
  22. void inc(int x, int y, int z, int d)
  23. {
  24.     for (int i = x; i < n; i = i | (i + 1))
  25.         for (int j = y; j < n; j = j | (j + 1))
  26.             for (int k = z; k < n; k = k | (k + 1))
  27.                 tree[i][j][k] += d;
  28. }
  29.  
  30. int sum(int x, int y, int z)
  31. {
  32.     int s = 0;
  33.     for (int i = x; i >= 0; i = (i&(i + 1)) - 1)
  34.         for (int j = y; j >= 0; j = (j&(j + 1)) - 1)
  35.             for (int k = z; k >= 0; k = (k&(k + 1)) - 1)
  36.                 s += tree[i][j][k];
  37.     return s;
  38. }
  39.  
  40. int sum(int x1, int y1, int z1, int x2, int y2, int z2)
  41. {
  42.     int s = sum(x2, y2, z2) - sum(x2, y2, z1 - 1) - sum(x2, y1 - 1, z2) - sum(x1 - 1, y2, z2) +sum(x1 - 1, y1 - 1, z2) + sum(x1 - 1, y2, z1 - 1) + sum(x2, y1 - 1, z1 - 1) - sum(x1 - 1, y1 - 1, z1 - 1);
  43.     return s;
  44. }
  45.  
  46.  
  47.  
  48. int main()
  49. {
  50.     ios_base::sync_with_stdio(0);
  51.     //freopen("input.txt", "r", stdin);//freopen("output.txt", "w", stdout);
  52.     // freopen("slalom.in", "r", stdin);freopen("slalom.out", "w", stdout);
  53.    
  54.  
  55.     //Фенвик ВСЕ ДЕЛО В ЕДИНИЦАХ!!!!
  56.    
  57.     cin >> n;
  58.  
  59.     int t, x1, y1, z1, x2, y2, z2, d;
  60.    
  61.     while (1)
  62.     {
  63.         cin >> t;
  64.         if (t == 3)
  65.             break;
  66.         if (t == 1)
  67.         {
  68.             cin >> x1 >> y1 >> z1 >> d;
  69.             inc(x1, y1, z1, d);
  70.         }
  71.         else
  72.         {
  73.             cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
  74.             cout << sum(x1, y1, z1, x2, y2, z2) << endl;
  75.         }
  76.     }
  77.  
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement