3D Bit Structure. Whats wrong with code?

3D Bit Structure. Whats wrong with code? 3D Bit Structure. Whats wrong with code?

#include<bits/stdc++.h> using namespace std; const long long mod = 100; long long n = 0; long long bit[mod + 1][mod + 1][mod + 1]; // Intialize tree void build() { for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) for (int z = 1; z <= n; z++) bit[i][j][z] = 0; } // Update void update(long long x, long long y, long long z, long long v) { long long ox = x, oy = y, oz = z; while(x <= n) { y = oy; while (y <= n) { z = oz; while (z <= n) { bit[x][y][z] += v; z += z&(-z); } y += y&(-y); } x += x&(-x); } } // Query long long query(long long x1, long long y1, long long z1, long long x2, long long y2, long long z2) { x1–, y1–, z1–; long long sum = 0, ox1 = x1, oy1 = y1, oz1 = z1, ox2 = x2, oy2 = y2, oz2 = z2; while(x2 > 0) { y2 = oy2; while (y2 > 0) { z2 = oz2; while (z2 > 0) { sum += bit[x2][y2][z2]; z2 -= z2&(-z2); } y2 -= y2&(-y2); } x2 -= x2&(-x2); } while(x1 > 0) { y1 = oy1; while (y1 > 0) { z1 = oz1; while (z1 > 0) { sum -= bit[x1][y1][z1]; z1 -= z1&(-z1); } y1 -= y1&(-y1); } x1 -= x1&(-x1); } return sum; } int main() { int t; cin >> t; while (t–) { int m; cin >> n >> m; while (m–) { string type; cin >> type; if (type == “UPDATE”) { long long x, y, z, v; cin >> x >> y >> z >> v; update(x, y, z, v); } else { long long x1, y1, z1, x2, y2, z2; cin >> x1 >> y1 >> z1 >> x2 >> y2 >> z2; cout << query(x1, y1, z1, x2, y2, z2) << “\n”; } } build(); } return 0; }

Can you yourself read this code?

I have formatted on on my side.

I have opened the collaboration mode here.

Please copy paste your code on CB ide and share the link. I can’t see what you have on your side.
Also, you don’t need to close and reopen the doubt again and again.

Look only at the query function of this code , and you will have to imagine and accept what is being returned in this solution. Please have a look once.

I used principle of inclusion exclusion for query, that your code used but it is still wrong. Here is the code https://ide.codingblocks.com/s/171604

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

why you closed? I still haven’t find problem in current code.

Did you find the difference.?
In a 3d structure, that’s how you need to implement. Try to imagine it

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.