题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3584

Cube

Problem Description

Given an N*N*N cube A, whose elements are either 0 or 1. A[i, j, k] means the number in the i-th row , j-th column and k-th layer. Initially we have A[i, j, k] = 0 (1 <= i, j, k <= N). 
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].

Input

Multi-cases.
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.

Output

For each query output A[x, y, z] in one line. (1<=n<=100 sum of m <=10000)

Sample Input

2 5

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

Sample Output

1

0

1

 /*AC代码*/
#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 ;
}

感觉三维应该和二维差不多   变一下下就好了

但是我就是wa了  囧 照例,下面的代码 请无视

 /*wa代码*/
#include<iostream> using namespace std; int N;
int c[][][]; int lowbit( int x )
{
return x & (-x);
} void update( int x, int y, int z, int delta )
{
int i, j , k;
for(i=x; i<=N; i+=lowbit(i))
{
for(j=y; j<=N; j+=lowbit(j))
{
for(k=z ; k<=N; k+=lowbit(j))
c[i][j][k] += delta;
}
}
} int sum( int x, int y , int z )
{
int res = , i, j , k;
for(i=x; i>; i-=lowbit(i))
{
for(j=y; j>; j-=lowbit(j))
{
for(k=z; k>; k-=lowbit(j))
{
res += c[i][j][k];
}
}
}
return res;
} void init ()
{
int i,j,k;
for(i=;i<=N;i++)
for(j=;j<=N;j++)
for(k=;k<=N;k++)
c[i][j][k]=;
} int main()
{
int x1,y1,z1,x2,y2,z2;
int temp,p; while(scanf("%d%d%",&N,&p)!=EOF)
{
init ();
while(p--)
{
scanf("%d",&temp);
if(temp==)
{
// printf("input x1~z2\n"); 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 if(temp==)
{
scanf("%d%d%d",&x1,&y1,&z1);
printf("%d\n",sum(x1,y1,z1)&);
}
}
} return ;
}

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

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

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

  2. HDU - 3584 Cube (三维树状数组 + 区间改动 + 单点求值)

    HDU - 3584 Cube Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Subm ...

  3. 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 ...

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

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

  5. HDU 3584 三维树状数组

    三维树状数组模版.优化不动了. #include <set> #include <map> #include <stack> #include <cmath& ...

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

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

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

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

  8. HDU 3333 | Codeforces 703D 树状数组、离散化

    HDU 3333:http://acm.hdu.edu.cn/showproblem.php?pid=3333 这两个题是类似的,都是离线处理查询,对每次查询的区间的右端点进行排序.这里我们需要离散化 ...

  9. HDU 3333 - Turing Tree (树状数组+离线处理+哈希+贪心)

    题意:给一个数组,每次查询输出区间内不重复数字的和. 这是3xian教主的题. 用前缀和的思想可以轻易求得区间的和,但是对于重复数字这点很难处理.在线很难下手,考虑离线处理. 将所有查询区间从右端点由 ...

  10. HDU 3333 Turing Tree (树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3333 题意就是询问区间不同数字的和. 比较经典的树状数组应用. //#pragma comment(l ...

随机推荐

  1. Linux+PHP+MySql网站迁移配置

    LINUX下MYSQL数据库默认数据库文件位置: 数据库文件默认在:cd /usr/share/mysql 配置文件默认在:/etc/my.cnf ———————————– 数据库目录:/var/li ...

  2. web项目中各种路径的获取

    以工程名为/DemoWeb为例: 访问的jsp为:http://localhost:8080/DemoWeb/test/index.jsp 1 JSP中获得当前应用的相对路径和绝对路径 (1)得到工程 ...

  3. REPL环境

    一.Node的REPL基本操作 REPL(Read-eval-print-loop):交互式解析器 在REPL环境下,可以定义和运行变量.函数.对象. REPL的常用命令: 进入node,即进入了RE ...

  4. javase-->基础知识(一)

    1.JDK安装和和配置 1)安装jdk1.8版本(不同的平台安装不同的jdk). 2)配置:将.../jdk1.x/bin放到path环境变量的最前面(避免之前配的环境变量干扰). ****** ja ...

  5. 51nod1459(带权值的dijkstra)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1459 题意:中文题诶- 思路:带权值的最短路,这道题数据也没 ...

  6. .net学习笔记----HttpRequest,WebRequest,HttpWebRequest区别

    WebRequest是一个虚类/基类,HttpWebRequest是WebRequest的具体实现 HttpRequest类的对象用于服务器端,获取客户端传来的请求的信息,包括HTTP报文传送过来的所 ...

  7. (2)WebAPI的增删改查

    using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Ne ...

  8. 解决select2在bootstrap的modal中默认不显示的问题

    在Bootstrap中的Modal,select2插件会有不显示,因为其z-index小于modal,还有另外一个问题是,修正z-index之后,select2不会自动失去焦点的问题.代码解决如下: ...

  9. 【leetcode】Add Binary

    题目简述: Given two binary strings, return their sum (also a binary string). For example, a = "11&q ...

  10. 责任链模式/chain of responsibility/行为型模式

    职责链模式 chain of responsibility 意图 使多个对象都有机会处理请求,从而避免请求的发送者和接受者之间的耦合关系.将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处 ...