三维树状数组模版。优化不动了。

#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#define Max 2505
#define FI first
#define SE second
#define ll long long
#define PI acos(-1.0)
#define inf 0x3fffffff
#define LL(x) ( x << 1 )
#define bug puts("here")
#define PII pair<int,int>
#define RR(x) ( x << 1 | 1 )
#define mp(a,b) make_pair(a,b)
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,s,t) for( int i = ( s ) ; i <= ( t ) ; ++ i ) using namespace std; int n , m ;
int c[101][101][101] ;
inline void RD(int &ret) {
char c;
do {
c = getchar();
} while(c < '0' || c > '9') ;
ret = c - '0';
while((c=getchar()) >= '0' && c <= '9')
ret = ret * 10 + ( c - '0' );
} inline void OT(int a) {
if(a >= 10)OT(a / 10) ;
putchar(a % 10 + '0') ;
}
void update(int x , int y ,int z) {
for (int i = x ; i <= n ; i += i & (-i) )
for (int j = y ; j <= n ; j += j & (-j))
for (int k = z ; k <= n ; k += k & (-k))
c[i][j][k] ++ ;
}
bool query(int x ,int y,int z) {
int ans = 0 ;
for (int i = x ; i >= 1 ; i -= i & (-i))
for (int j = y ; j >=1 ; j -= j & (-j))
for (int k = z ; k >= 1 ; k -= k & (-k))
ans += c[i][j][k] ;
return ans & 1 ;
}
void init() {
for (int i = 0 ; i <= n ; i ++ )
for (int j = 0 ; j <= n ; j ++ )
for (int k = 0 ; k <= n ; k ++ )
c[i][j][k] = 0 ;
}
int main() {
int x , y , z ;
int xx , yy , zz ;
int op ;
while(scanf("%d%d",&n,&m) == 2) { while(m -- ) {
RD(op) ;
if(op & 1) {
RD(x) ;RD(y) ;RD(z) ;
RD(xx) ;RD(yy) ;RD(zz) ;
update(x , y , z ) ;
update(xx + 1 , y , z ) ;
update(xx + 1 , yy + 1 , z ) ;
update(xx + 1 , yy + 1 , zz + 1 ) ;
update(xx + 1 , y , zz + 1 ) ;
update(x , y , zz + 1 ) ;
update(x , yy + 1 , zz + 1 ) ;
update(x , yy + 1 , z ) ;
} else {
RD(x) ;RD(y) ;RD(z) ;
OT(query(x , y , z)) ;
putchar('\n') ;
}
}
init() ;
}
return 0 ;
}

HDU 3584 三维树状数组的更多相关文章

  1. HDU 3584 Cube 【 三维树状数组 】

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

  2. HDU 3584 Cube (三维树状数组)

    Problem Description Given an N*N*N cube A, whose elements are either 0 or 1. A[i, j, k] means the nu ...

  3. 1470. UFOs(三维树状数组)

    1470 最简单的三维树状数组 #include <iostream> #include<cstdio> #include<cstring> #include< ...

  4. 暴力三维树状数组求曼哈顿距离求最值——牛客多校第八场D

    涉及的知识点挺多,但是大多是套路 1.求曼哈顿距离的最值一般对所有情况进行讨论 2.三维树状数组用来求前缀最大值 /* 有一个三维坐标系(x,y,z),取值范围为[1,n],[1,m],[1,h],有 ...

  5. HDU 3584 Cube --三维树状数组

    题意:给一个三维数组n*n*n,初始都为0,每次有两个操作: 1. 翻转(x1,y1,z1) -> (x2,y2,z2) 0. 查询A[x][y][z] (A为该数组) 解法:树状数组维护操作次 ...

  6. HDU 2689Sort it 树状数组 逆序对

    Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  7. HDU 2838 (DP+树状数组维护带权排序)

    Reference: http://blog.csdn.net/me4546/article/details/6333225 题目链接: http://acm.hdu.edu.cn/showprobl ...

  8. hdu 4046 Panda 树状数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4046 When I wrote down this letter, you may have been ...

  9. hdu 5497 Inversion 树状数组 逆序对,单点修改

    Inversion Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5497 ...

随机推荐

  1. mvc导航配置

    <?xml version="1.0" encoding="utf-8" ?><Configuration> <Navigatio ...

  2. vim常用操作技巧与配置

    vi是linux与unix下的常用文本编辑器,其运行稳定,使用方便,本文将分两部分对其常用操作技巧和配置进行阐述,其中参考了网上的一些文章,对作者表示感谢 PART1 操作技巧 说明: 以下的例子中  ...

  3. Struts2、spring2、hibernate3在SSH中各起什么作用

    简单的说: struts 控制用的 hibernate 操作数据库的 spring用解耦的 详细的说: STRUTS 在 SSH 框架中起控制的作用 , 其核心是 Controller, 即 Acti ...

  4. android getDecorView()的作用

    decorView是window中的最顶层view,可以从window中通过getDecorView获取到decorView.通过decorView获取到程序显示的区域,包括标题栏,但不包括状态栏.间 ...

  5. springmvc中使用response的out.print问题

    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws E ...

  6. 引用 移植Linux到s3c2410上

    引用 bsky 的 移植Linux到s3c2410上来源:http://www.embed.com.cn/downcenter/Article/Catalog12/4000.htm 移植Linux到s ...

  7. 转:Javascript的10个设计缺陷

    作者: 阮一峰 日期: 2011年6月30日 前几篇文章,我经常说Javascript的设计不够严谨,有很多失误. 今天的这一篇,前半部分就谈为什么会这样,后半部分将列举Javascript的10个设 ...

  8. Net::OpenSSH 模块使用

    use Net::OpenSSH; my $host = "$ip"; my $user = 'root'; my $passphrase = 'uxxxxxD'; my $key ...

  9. CMAKE的使用

    CMAKE的使用 Version 1.0 2009-3-18 一.      基本使用 安装:下载二进制包后可直接解压使用 从源码安装则执行命令:./bootstrap; make; make ins ...

  10. hdu1397(素数组和成偶数的个数 用 标记法)

    Problem Description Goldbach's Conjecture: For any even number n greater than or equal to 4, there e ...