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] 比 [ ...
随机推荐
- Git 以分支的方式同时管理多个项目
你是否遇到过这样的问题: 你的客户在你们这边做了N个项目,而项目之间又存在着某些业务关联(数据库访问等) 之前你可能是这样处理的,为客户的每个项目创建单独的Git版本 PC项目 手机项目 微信项目 其 ...
- disconf-自动注入属性变化
disconf-自动注入属性变化 disconf官网:http://disconf.readthedocs.io/zh_CN/latest/ 自动注入属性:http://disconf.readthe ...
- (转)mobile cpu上禁用alpha test的相关总结
转自:http://www.cnblogs.com/TracePlus/p/4037165.html 因为,每家芯片的特性不同,根据向framebuffer写法的不同,分为tile-based的mob ...
- Angular入门笔记
AngularJS(下面简称其为ng)是Google开源的一款JavaScript MVC框架,弥补了HTML在构建应用方面的不足,其通过使用指令(directives)结构来扩展HTML词汇,使开发 ...
- Hibernate: No Session found for current thread
在Struts2+Hibernate+Srping项目中经常会遇到这种问题 我知道的一种情况是: Spring的事务配置中没有配置好异常出现处的路径 <aop:advisor pointcut= ...
- 关于extern "C"(详细剖析)
[目录] 引言 extern “C”的前世今生 小心门后的未知世界 Q&A c++调用c的方法 c调用c++的方法 在你工作过的系统里,不知能否看到类似下面的代码. 这好像没有什么问题,你应该 ...
- intel vt
EPT和VPID技术是内存虚拟化技术, 是页表扩充技术Extended Page Table (EPT) 的缩写, 是VT-x技术的一部分. 内存虚拟化的主要任务是实现地址空间的虚拟化,内存虚拟化是通 ...
- POI3.10读取Excel模板填充数据后生成新的Excel文件
private final DecimalFormat df = new DecimalFormat("#0.00"); public void test(){ String fi ...
- stingray中modal window
自定义内容modal window //show window for D&B suggestions function showDBMatch(resp) { console.log('xx ...
- JavaScript正则式练习
使用正则式匹配第一个数字和最后一个数字,使用环视 str2 = 09051 : Fast Food Restaurants - Concession Stands/Snack Bars Delicat ...