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] 比 [ ...
随机推荐
- Java——DOM方式生成XML (转)
http://blog.csdn.net/u012325167/article/details/50943202 使用DOM方式生成XML文件有如下几步: 首先是创建DOM树(即规定XML文件中的内容 ...
- VIM的buffers
原文:http://ju.outofmemory.cn/entry/13522 重新在不同的 tab 中打开多个关闭的buffer 文件, https://stackoverflow.com/ques ...
- gl.h included before glew.h
So I'm trying to move my OpenGL code from Main() into a specific class that will handle the 3D gra ...
- 将java项目打包成docker镜像:镜像=副本
简介:将jar打包成镜像好说,毕竟jar包长的都是一样的,但是我们只是写了一个普通的java项目,我也不方便封装成jar包什么的,但是我们也想打包docker image怎么办呢,我们可以用编译后的j ...
- 【Python】torrentParser1.01
在昨天的版本上做了一些改进,如增加getAll,修改getSingleFileName等 代码: #-------------------------------------------------- ...
- Solidworks公司电脑图纸被加密之后如何解密输出
第一步:打开总装配的组件(该组件需要包含你所有需要的零件),比如打开其中一个: 第二步:Solidworks的菜单中依次:"文件"→"打包"(有的版本是pa ...
- asp.net 除法保留小数
(Convert.ToDouble(num1)/Convert.ToDouble(num2)).ToString("0.00"); .只要求保留N位不四舍5入 float f = ...
- LintCode: 3 Sum
C++ 把3个数求和,转变为2个数求和 1. 把数组排序 2. 注意过滤重复值 3. 从前到后遍历,游标i 4. 从后边数中找start + end = -arr[i]的2 sum 5. start ...
- 使用Newtonsoft进行JSON序列化时将枚举序列化为字符串的方法
一.实体书写 将枚举类型的属性前面加上[JsonConverter(typeof(StringEnumConverter))]即可. 二.举例 [JsonConverter(typeof(String ...
- SQL Server复制故障(1)
初始化时报错 错误消息: The process could not read file '\\176WINDOWSSQL\ReplData\unc\176WINDOWSSQL_DB2_TEST3\2 ...