HDU 3584 Cube (三维数状数组)
Cube
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 1166 Accepted Submission(s): 580
We define two operations, 1: “Not” operation that we change the A[i, j, k]=!A[i, j, k]. that means we change A[i, j, k] from 0->1,or 1->0. (x1<=i<=x2,y1<=j<=y2,z1<=k<=z2).
0: “Query” operation we want to get the value of A[i, j, k].
First line contains N and M, M lines follow indicating the operation below.
Each operation contains an X, the type of operation. 1: “Not” operation and 0: “Query” operation.
If X is 1, following x1, y1, z1, x2, y2, z2.
If X is 0, following x, y, z.
1 1 1 1 1 1 1
0 1 1 1
1 1 1 1 2 2 2
0 1 1 1
0 2 2 2
0
1
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int N=; int n,m,arr[N][N][N]; int lowbit(int x){
return x&(-x);
} void update(int i,int j,int k,int val){
while(i<=n){
int tmpj=j;
while(tmpj<=n){
int tmpk=k;
while(tmpk<=n){
arr[i][tmpj][tmpk]+=val;
tmpk+=lowbit(tmpk);
}
tmpj+=lowbit(tmpj);
}
i+=lowbit(i);
}
} int Sum(int i,int j,int k){
int ans=;
while(i>){
int tmpj=j;
while(tmpj>){
int tmpk=k;
while(tmpk>){
ans+=arr[i][tmpj][tmpk];
tmpk-=lowbit(tmpk);
}
tmpj-=lowbit(tmpj);
}
i-=lowbit(i);
}
return ans;
} int main(){ //freopen("input.txt","r",stdin); while(~scanf("%d%d",&n,&m)){
memset(arr,,sizeof(arr));
int x1,y1,z1,x2,y2,z2;
int op;
while(m--){
scanf("%d",&op);
if(op==){
scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
update(x2+, y2+, z2+, );
update(x1, y2+, z2+, );
update(x2+, y1, z2+, );
update(x2+, y2+, z1, );
update(x1, y1, z2+, );
update(x2+, y1, z1, );
update(x1, y2+, z1, );
update(x1, y1, z1, );
}else {
scanf("%d%d%d",&x1,&y1,&z1);
printf("%d\n",Sum(x1,y1,z1)&); //该点的值就是sum(x,y)
}
}
}
return ;
}
HDU 3584 Cube (三维数状数组)的更多相关文章
- HDU - 3584 Cube (三维树状数组 + 区间改动 + 单点求值)
HDU - 3584 Cube Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Subm ...
- HDU 3584 Cube --三维树状数组
题意:给一个三维数组n*n*n,初始都为0,每次有两个操作: 1. 翻转(x1,y1,z1) -> (x2,y2,z2) 0. 查询A[x][y][z] (A为该数组) 解法:树状数组维护操作次 ...
- HDU 1394Minimum Inversion Number 数状数组 逆序对数量和
Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 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 ...
- HDU 3584 Cube 【 三维树状数组 】
题意:还是那篇论文里面讲到的,三维树状数组http://wenku.baidu.com/view/1e51750abb68a98271fefaa8画个立方体出来对照一下好想一点 #include< ...
- HDU 3584 三维树状数组
三维树状数组模版.优化不动了. #include <set> #include <map> #include <stack> #include <cmath& ...
- HDU 1166 敌兵布阵 (数状数组,或线段树)
题意:... 析:可以直接用数状数组进行模拟,也可以用线段树. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000&quo ...
- 1470. UFOs(三维树状数组)
1470 最简单的三维树状数组 #include <iostream> #include<cstdio> #include<cstring> #include< ...
- poj 2481 Cows(数状数组 或 线段树)
题意:对于两个区间,[si,ei] 和 [sj,ej],若 si <= sj and ei >= ej and ei - si > ej - sj 则说明区间 [si,ei] 比 [ ...
随机推荐
- css文件放在根目录之后不起作用原因
修改为
- (转)总结使用Unity 3D优化游戏运行性能的经验
http://www.199it.com/archives/147913.html 流畅的游戏玩法来自流畅的帧率,而我们即将推出的动作平台游戏<Shadow Blade>已经将在标准iPh ...
- Flask调试
1.AttributeError: 'NoneType' object has no attribute 'app' 原因:直接在py中调用视图函数,但没有上下文,导致出错 2.不转换html代码 { ...
- eclipse启动错误:java.lang.NoClassDefFoundError: org/eclipse/core/resources/IContainer
转自:http://blog.csdn.net/niu_hao/article/details/9332521 eclipse启动时报错如下:java.lang.NoClassDefFoundErro ...
- SQL还原后:目录名称无效
使用Sql Server备份文件,还原数据库出现如下错误:目录名称无效 解决方法:在系统临时文件夹内,如C:\Users\Administrator\AppData\Local\Temp\ 下新建名称 ...
- 获取和设置URL里星号(#)的参数
示例:http://gzmsg.com/go/news.aspx#page=12 var DF = {}; (function () { var a = function () { var d, e ...
- 编程之美 1.1 让cpu占用率曲线听你指挥(多核处理器)
[目录] 不考虑其他进程,cpu画正弦曲线 获取总体cpu利用率 获取多核处理器单个cpu利用率 考虑其他进程,cpu画正弦曲线 下面的程序针对多核处理器,可以设置让任何一个cpu显示相应的曲线(本文 ...
- WIP 001 - design the applicant screen
In this item, you only need to design the screen
- SpringMVC学习笔记六:使用Formatter解析或格式化数据
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6832903.html Converter可以将一种类型转换成另一种类型,是任意Object之间的类型 ...
- Changing the Language Used in ODI Studio
odi.conf中加入区域和语言设置 修改 "$ODI_HOME\odi\studio\bin\odi.conf" ( D:\Oracle\Middleware\Oracle ...