HDU 3584 Cube 【 三维树状数组 】

时间:2021-02-15 09:18:55

题意:还是那篇论文里面讲到的,三维树状数组
http://wenku.baidu.com/view/1e51750abb68a98271fefaa8
画个立方体出来对照一下好想一点

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue> a
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=;
const int N=; int n,m;
int a[][][],c[][][]; int lowbit(int x){ return x & (-x);} int sum(int x,int y,int z){
int ret=;
for(int i=x;i>;i-=lowbit(i))
for(int j=y;j>;j-=lowbit(j))
for(int k=z;k>;k-=lowbit(k))
ret+=c[i][j][k]; return ret;
} void add(int x,int y,int z,int d){
for(int i=x;i<=N;i+=lowbit(i))
for(int j=y;j<=N;j+=lowbit(j))
for(int k=z;k<=N;k+=lowbit(k))
c[i][j][k] += d;
} int main(){
while(scanf("%d %d",&n,&m) != EOF){
memset(c,,sizeof(c));
while(m--){
int cmd;
scanf("%d",&cmd);
if(cmd == ){
int x1,y1,z1,x2,y2,z2;
scanf("%d %d %d %d %d %d",&x1,&y1,&z1,&x2,&y2,&z2);
x1++;y1++;z1++;
x2++;y2++;z2++;
add(x1,y1,z1,);
add(x2+,y1,z1,-);
add(x1,y2+,z1,-);
add(x2+,y2+,z1,); add(x1,y1,z2+,-);
add(x2+,y1,z2+,);
add(x1,y2+,z2+,);
add(x2+,y2+,z2+,-);
}
else{
int x,y,z;
scanf("%d %d %d",&x,&y,&z);
x++;y++;z++;
printf("%d\n",sum(x,y,z) % );
}
}
}
return ;
}