-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3-D Fenwick Tree.cpp
More file actions
75 lines (75 loc) · 1.6 KB
/
3-D Fenwick Tree.cpp
File metadata and controls
75 lines (75 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <cstdio>
#include <cctype>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <fstream>
#include <ctime>
#include <cassert>
#include <cstring>
using namespace std;
#define MAX 135
long long tree[MAX][MAX][MAX];
void update(int x,int y,int z,int K)
{
while(x<MAX){
int i=y;
while(i<MAX){
int j=z;
while(j<MAX){
tree[x][i][j]+=K;
j+=(j&-j);
}
i+=(i&-i);
}
x+=(x&-x);
}
}
long long querry(int x2,int y2,int z2)
{
long long sum=0;
while(x2>0){
int i=y2;
while(i>0){
int j=z2;
while(j>0){
sum+=tree[x2][i][j];
j-=(j&-j);
}
i-=(i&-i);
}
x2-=(x2&-x2);
}
return sum;
}
int main()
{
int N;
scanf("%d",&N);
memset(tree,0,sizeof(tree));
while(1){
int M;
scanf("%d",&M);
if(M==1){
int x,y,z,K;
scanf("%d %d %d %d",&x,&y,&z,&K);
update(x+1,y+1,z+1,K);
}
else if(M==2){
int x1,y1,z1,x2,y2,z2;
scanf("%d %d %d %d %d %d",&x1,&y1,&z1,&x2,&y2,&z2);
long long m=querry(x2+1,y2+1,z2+1)-querry(x1,y2+1,z2+1)-querry(x2+1,y1,z2+1) - querry(x2+1, y2+1, z1) -querry(x1, y1, z1) + querry(x1, y1, z2+1) + querry(x1, y2+1, z1) + querry(x2+1, y1, z1);
printf("%lld\n",m);
}
else
break;
}
return 0;
}