Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. #include <functional>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <iomanip>
  6. #include <sstream>
  7. #include <numeric>
  8. #include <string>
  9. #include <vector>
  10. #include <bitset>
  11. #include <queue>
  12. #include <stack>
  13. #include <map>
  14. #include <set>
  15. #include <cstdlib>
  16. #include <cassert>
  17. #include <cstring>
  18. #include <cstdio>
  19. #include <cmath>
  20. #include <ctime>
  21. #include <list>
  22.  
  23. using namespace std;
  24.  
  25. typedef long long LL;
  26. typedef long double LD;
  27. typedef pair<int, int> pii;
  28.  
  29. const LD eps = 1e-9;
  30. const LD pi = acos(-1.0);
  31. const LL inf = 1e+9;
  32.  
  33. #define mp make_pair
  34. #define pb push_back
  35. #define X first
  36. #define Y second
  37.  
  38. #define dbg(x) { cerr << #x << " = " << x << endl; }
  39.  
  40. // extended template
  41. #pragma comment(linker, "/STACK:36777216")
  42. typedef vector<int> vi;
  43. typedef vector<vi> vvi;
  44.  
  45. #define forn(i, n) for (int i = 0; i < n; ++i)
  46. #define all(a) (a).begin(), (a).end()
  47. #define rall(a) (a).rbegin(), (a).rend()
  48.  
  49. template<typename T> istream & operator >> (istream &, vector<T> &);
  50. template<typename T> ostream & operator << (ostream &, const vector<T> &);
  51.  
  52. #define START clock_t _clock = clock();
  53. #define END cerr << endl << "time: " << (clock() - _clock) / LD(CLOCKS_PER_SEC) << endl;
  54.  
  55. #define NAME "problem"
  56.  
  57. vector <vector<vector <LL> > > t;
  58.  
  59.  
  60. void inc(int x, int y, int z, int add)
  61. {
  62. for (int i = x; i < t.size(); i = (i | (i + 1)))
  63. {
  64. for (int k = y; k < t[0].size(); k = (k | (k + 1)))
  65. {
  66. for (int j = z; j < t[0][0].size(); j = (j | (j + 1)))
  67. {
  68. t[i][k][j] += add;
  69. }
  70. }
  71. }
  72. }
  73.  
  74. LL sum(int x, int y, int z)
  75. {
  76. LL s = 0;
  77. for (int i = x; i >= 0; i = (i & (i + 1)) - 1)
  78. {
  79. for (int k = y; k >= 0; k = (k & (k + 1)) - 1)
  80. {
  81. for (int j = z; j >= 0; j = (j & (j + 1)) - 1)
  82. {
  83. s += t[i][k][j];
  84. }
  85. }
  86. }
  87. return s;
  88. }
  89.  
  90. LL sum(int x, int y, int z, int x2, int y2, int z2)
  91. {
  92. return sum(x2, y2, z2) - sum(x - 1, y2, z2) - sum(x2, y - 1, z2) - sum(x2, y2, z - 1) + sum(x - 1, y - 1, z2) + sum(x - 1, y2, z - 1) + sum(x2, y - 1, z - 1) - sum(x - 1, y - 1, z - 1) ;
  93. }
  94.  
  95. int main()
  96. {
  97. //freopen("input.txt", "r", stdin);
  98. freopen("stars.in", "r", stdin); freopen("stars.out", "w", stdout);
  99. int n, m;
  100. cin >> n;
  101. t.assign(n, vector <vector<LL> >(n, vector <LL> (n, 0)));
  102. int t = 0;
  103. while (cin >> t)
  104. {
  105. if (t == 3)
  106. break;
  107. if (t == 1)
  108. {
  109. int x, y, z, add;
  110. cin >> x >> y >> z >> add;
  111. //x--;y--;z--;
  112. inc(x, y, z, add);
  113. }
  114. else
  115. {
  116. int x, y, z, x2, y2, z2;
  117. cin >> x >> y >> z >> x2 >> y2 >> z2;
  118. cout << sum(x, y, z, x2, y2, z2) << endl;
  119. }
  120. }
  121.  
  122.  
  123. return 0;
  124. }
  125. /*******************************************
  126. *******************************************/
  127.  
  128. template<typename T> istream & operator >> (istream &is, vector<T> &v)
  129. {
  130. forn(i, v.size())
  131. is >> v[i];
  132. return is;
  133. }
  134. template<typename T> ostream & operator << (ostream &os, const vector<T> &v)
  135. {
  136. forn(i, v.size())
  137. os << v[i] << " ";
  138. return os;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement