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] 比 [ ...
随机推荐
- Kafka:ZK+Kafka+Spark Streaming集群环境搭建(二十四)Structured Streaming:Encoder
一般情况下我们在使用Dataset<Row>进行groupByKey时,你会发现这个方法最后一个参数需要一个encoder,那么这些encoder如何定义呢? 一般数据类型 static ...
- [Algorithm] Reservoir Sampling
Given a stream of elements too large to store in memory, pick a random element from the stream with ...
- 使用CSS3生成的电子时钟特效
在线演示 本地下载 突然觉得自己对带工作的态度亟需改正,虽然不喜欢现在的加班生活,但是自己要去接受自己不喜欢的,才能获得自己喜欢的. 这是自己好久之前丛过的一个时钟,网上应该有这个的教程,虽然实现的效 ...
- Office办公 WPS如何设置页边距
打开页眉页脚,在选项里面可以设置顶部的一行文字距离边界的距离 此外在页面布局,页边距也可以查看和修改
- IO multiplexing 与 非阻塞网络编程
使用I/O multipexing 的网络编程中,一般需要采用非阻塞网络编程的风格,防止服务端在处理高连接量大时候阻塞在某个文件描述符上面,比如某个socket 有大量的数据需要写,但是内核发送缓冲区 ...
- Qt,Qt/E,Qtopia Core, Qtopia之间的区别和联系
转自:http://www.qtcn.org/bbs/read.php?tid=10373 关于Qt,Qt/E,Qtopia Core, Qtopia这些版本之间的区别和联系: Qt泛指Qt的所有桌面 ...
- Android开之在非UI线程中更新UI
当在非UI线程中更新UI(程序界面)时会出现例如以下图所看到的的异常: 那怎样才干在非UI线程中更细UI呢? 方法有非常多种.在这里主要介绍三种: 第一种:调用主线程mHandler的post(Run ...
- 一个简单的 JSON 生成/解析库
这是一个单文件的,适用于C语言的, JSON 读写库. 先说明,不想造轮子,代码是从这里拿来的: https://www.codeproject.com/Articles/887604/jWrite- ...
- C#实现发布订阅模式
首先给出项目的结构 IPublish.cs的源码: namespace NsWebChat.PublishSubscribe { /// <summary> /// 发布事件基础接口 // ...
- V-rep学习笔记:串口操作
VREP Regular API提供了串口操作的相关函数,可以对串口进行打开.关闭和读写: 下面使用一款淘宝上常见的AHRS(Attitude and heading reference system ...