TYVJ 1476 三维树状数组
裸题~
注意三维的前缀体积怎么算就好
View Code
1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 5 #define N 120 6 7 using namespace std; 8 9 int n,c[N][N][N]; 10 11 inline int lowbit(int x) 12 { 13 return x&-x; 14 } 15 16 void updata(int x,int y,int z,int dt) 17 { 18 while(x<=n) 19 { 20 int y1=y; 21 while(y1<=n) 22 { 23 int z1=z; 24 while(z1<=n) 25 { 26 c[x][y1][z1]+=dt; 27 z1+=lowbit(z1); 28 } 29 y1+=lowbit(y1); 30 } 31 x+=lowbit(x); 32 } 33 } 34 35 int getsum(int x,int y,int z) 36 { 37 int rt=0; 38 while(x) 39 { 40 int y1=y; 41 while(y1) 42 { 43 int z1=z; 44 while(z1) 45 { 46 rt+=c[x][y1][z1]; 47 z1-=lowbit(z1); 48 } 49 y1-=lowbit(y1); 50 } 51 x-=lowbit(x); 52 } 53 return rt; 54 } 55 56 void read() 57 { 58 scanf("%d",&n); 59 int pd,x,y,z,x1,y1,z1,p,s; 60 while(scanf("%d",&pd)) 61 { 62 if(pd==3) break; 63 if(pd==1) 64 { 65 scanf("%d%d%d%d",&x,&y,&z,&p); 66 x++; y++; z++; 67 updata(x,y,z,p); 68 } 69 else 70 { 71 scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x,&y,&z); 72 x++; y++; z++; 73 s=getsum(x,y,z)-getsum(x,y,z1)-getsum(x,y1,z)-getsum(x1,y,z); 74 s=s+getsum(x1,y1,z)+getsum(x1,y,z1)+getsum(x,y1,z1); 75 s=s-getsum(x1,y1,z1); 76 printf("%d\n",s); 77 } 78 } 79 } 80 81 int main() 82 { 83 read(); 84 return 0; 85 }
没有人能阻止我前进的步伐,除了我自己!