http://acm.hdu.edu.cn/showproblem.php?pid=3584
三维差分数组+三维树状数组
复杂度应该是O(m * logn * logn * logn)
/*
小心多组
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<queue>
#include<algorithm>
#define ll long long
#define pb push
#define test printf("here!!!")
using namespace std;
const int mx=100+10;
const ll mod=1e9+7;
int n,m;
int a[mx][mx][mx];
int lowbit(int x)
{
return x&-x;
}
void updata(int x,int y,int z,int c)
{
int yy=y,zz=z;
while (x<=n)
{
y=yy;
while (y<=n)
{
z=zz;
while (z<=n)
{
a[x][y][z]+=c;
z+=lowbit(z);
}
y+=lowbit(y);
}
x+=lowbit(x);
}
}
int query(int x,int y,int z)
{
int res=0;
int yy=y,zz=z;
while (x)
{
y=yy;
while (y)
{
z=zz;
while (z)
{
res+=a[x][y][z];
z-=lowbit(z);
}
y-=lowbit(y);
}
x-=lowbit(x);
}
return res;
}
int main()
{
int x,x2,y,y2,z,z2;
int op;
while (~scanf("%d%d",&n,&m))
{
memset(a,0,sizeof(a));
while (m--)
{
scanf("%d",&op);
if (op)
{
scanf("%d%d%d%d%d%d",&x,&y,&z,&x2,&y2,&z2);
updata(x,y,z,1);
updata(x,y2+1,z,-1);
updata(x2+1,y,z,-1);
updata(x2+1,y2+1,z,1);
updata(x,y,z2+1,-1);
updata(x,y2+1,z2+1,1);
updata(x2+1,y,z2+1,1);
updata(x2+1,y2+1,z2+1,-1);
}
else
{
scanf("%d%d%d",&x,&y,&z);
printf("%d\n",query(x,y,z)&1);
}
}
}
}
二维差分+二维树状数组划水版
复杂度应该是O(m * n * logn * logn)
/*
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<queue>
#include<algorithm>
#define ll long long
#define pb push
#define test printf("here!!!")
using namespace std;
const int mx=100+10;
const ll mod=1e9+7;
int n,m;
int a[mx][mx][mx];
int lowbit(int x)
{
return x&-x;
}
void updata(int x,int y,int z,int c)
{
int yy=y;
while (x<=n)
{
y=yy;
while (y<=n)
{
a[x][y][z]+=c;
y+=lowbit(y);
}
x+=lowbit(x);
}
}
int query(int x,int y,int z)
{
int res=0;
int yy=y;
while (x)
{
y=yy;
while (y)
{
res+=a[x][y][z];
y-=lowbit(y);
}
x-=lowbit(x);
}
return res;
}
int main()
{
int x,x2,y,y2,z,z2;
int op;
while (~scanf("%d%d",&n,&m))
{
memset(a,0,sizeof(a));
while (m--)
{
scanf("%d",&op);
if (op)
{
scanf("%d%d%d%d%d%d",&x,&y,&z,&x2,&y2,&z2);
for (int i=z;i<=z2;++i)
{
updata(x,y,i,1);
updata(x,y2+1,i,-1);
updata(x2+1,y,i,-1);
updata(x2+1,y2+1,i,1);
}
}
else
{
scanf("%d%d%d",&x,&y,&z);
printf("%d\n",query(x,y,z)&1);
}
}
}
}