概述
/* THE PROGRAM IS MADE BY PYY */
/*----------------------------------------------------------------------------//
Copyright (c) 2012 panyanyany All rights reserved.
URL : http://acm.hdu.edu.cn/showproblem.php?pid=3584
Name : 3584 Cube
Date : Monday, April 16, 2012
Time Stage : one hour
Result:
5786208 2012-04-16 20:21:21 Accepted 3584
140MS 5436K 2090 B
C++ pyy
Test Data :
Review :
我觉得getsum(x)&1 和 (getsum(x) – getsum(x-1))&1 效果应该一样才对啊,怎么后者会WA呢……
有请大牛的博客:
http://hi.baidu.com/496587701/blog/item/298d2ad672d55c20960a1613.html
//----------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std ;
#define MEM(a, v) memset (a, v, sizeof (a)) // a for address, v for value
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define INF (0x3f3f3f3f)
#define MAXN 110
#define LESN 10002
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)|1)
#define DB /##/
typedef __int64 LL;
int n, m;
int treeArr[MAXN][MAXN][MAXN];
inline int lowbit(int x)
{
return x & (-x);
}
void add(int x, int y, int z, int val)
{
int i, j;
while (x <= n)
{
i = y;
while (i <= n)
{
j = z;
while (j <= n)
{
treeArr[x][i][j] += val;
j += lowbit(j);
}
i += lowbit(i);
}
x += lowbit(x);
}
}
int getsum(int x, int y, int z)
{
int sum = 0;
int i, j;
while (x > 0)
{
i = y;
while (i > 0)
{
j = z;
while (j > 0)
{
sum += treeArr[x][i][j];
j -= lowbit(j);
}
i -= lowbit(i);
}
x -= lowbit(x);
}
return sum;
}
int main()
{
int i, f, x, y, z, xx, yy, zz;
while (scanf("%d %d", &n, &m) != EOF)
{
MEM(treeArr, 0);
for (i = 0; i < m; ++i)
{
scanf("%d %d %d %d", &f, &x, &y, &z);
if (0 == f)
{
printf("%dn", getsum(x, y, z) & 1);
}
else
{
scanf("%d %d %d", &xx, &yy, &zz);
add(x, y, z, 1);
add(xx+1, y, z, -1);
add(x, yy+1, z, -1);
add(x, y, zz+1, -1);
add(xx+1, yy+1, z, 1);
add(xx+1, y, zz+1, 1);
add(x, yy+1, zz+1, 1);
add(xx+1, yy+1, zz+1, -1);
}
}
}
return 0;
}
最后
以上就是淡定毛衣为你收集整理的【树状数组+三维】杭电 hdu 3584 Cube的全部内容,希望文章能够帮你解决【树状数组+三维】杭电 hdu 3584 Cube所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复