Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <map>
- #include <algorithm>
- #include <queue>
- #include <stack>
- #include <set>
- #include <math.h>
- #define forn(i, n) for(int i = 0; i < int(n); i++)
- using namespace std;
- int n;
- int f[128][128][128];
- void inc (int x, int y, int z, int d) {
- for (int i = x; i < n; i = i | (i + 1))
- for (int j = y; j < n; j = j | (j + 1))
- for (int k = z; k < n; k = k | (k + 1))
- f[i][j][k] += d;
- }
- int sum (int x, int y, int z) {
- int res = 0;
- for (int i = x; i >= 0; i = (i & (i + 1)) - 1)
- for (int j = y; j >= 0; j = (j & (j + 1)) - 1)
- for (int k = z; k >= 0; k = (k & (k + 1)) - 1)
- res += f[i][j][k];
- return res;
- }
- int main () {
- cin >> n;
- int t;
- while (cin >> t) {
- if (t == 3)
- break;
- if (t == 1) {
- int x, y, z, k;
- cin >> x >> y >> z >> k;
- inc(x, y, z, k);
- }
- if (t == 2) {
- int x1, y1, z1, x2, y2, z2;
- cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
- cout << sum(x2, y2, z2)
- - sum(x1 - 1, y2, z2)
- - sum(x2, y1 - 1, z2)
- - sum(x2, y2, z1 - 1)
- + sum(x1 - 1, y2, z1 - 1)
- + sum(x1 - 1, y1 - 1, z2)
- + sum(x2, y1 - 1, z1 - 1)
- - sum(x1 - 1, y1 - 1, z1 - 1) << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement