Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- typedef long long ll;
- using namespace std;
- struct fenwick {
- int n, m, k;
- vector<vector<vector<int>>> t;
- fenwick(int _n, int _m, int _k) {
- n = _n; m = _m; k = _k;
- t.resize(n, vector<vector<int>>(m, vector<int>(k, 0)));
- }
- ll sum(int x, int y, int z) {
- ll result = 0;
- for (; x >= 0; x &= (x + 1), --x) {
- for (; y >= 0; y &= (y + 1), --y) {
- for (; z >= 0; z &= (z + 1), --z) {
- result += t[x][y][z];
- }
- }
- }
- return result;
- }
- void upd(int x, int y, int z, int delta) {
- for (; x < n; x |= (x + 1)) {
- for (; y < m; y |= (y + 1)) {
- for (; z < k; z |= (z + 1)) {
- t[x][y][z] += delta;
- }
- }
- }
- }
- };
- int main() {
- fast
- file_in
- // file_in_out
- int n;
- cin >> n;
- fenwick f(n, n, n);
- int type, x, y, z, k, x1, y1, z1, x2, y2, z2;
- while (true) {
- cin >> type;
- if (type == 1) {
- cin >> x >> y >> z >> k;
- f.upd(x, y, z, k);
- }
- if (type == 2) {
- cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2;
- ll f1 = f.sum(x2, y2, z2) + f.sum(x1 - 1, y1 - 1, z2) + f.sum(x2, y1 - 1, z1 - 1) + f.sum(x1 - 1, y2, z1 - 1);
- ll f2 = f.sum(x1 - 1, y1 - 1, z1 - 1) + f.sum(x2, y1 - 1, z2) + f.sum(x1 - 1, y2, z2) + f.sum(x2, y2, z1 - 1);
- cout << f1 - f2 << "\n";
- }
- if (type == 3) {
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment