题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=3584

题目大意:

给定一个N*N*N多维数据集A,其元素是0或是1。A[i,j,k]表示集合中第
i 行,第 j 列与第 k 层的值。

首先由A[i,j,k] = 0(1 <= i,j,k <= N)。

给定两个操作:

1:改变A[i,j,k]为!A[i,j,k]。

2:查询A[i,j,k]的值。

解题思路:

三维树状数组模拟,利用容斥原理

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<list>
#include<deque>
#include<sstream>
#include<cctype>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, s, t) for(int i = (s); i < (t); i++)
#define MEM(a, x) memset(a, x, sizeof(a));
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const double eps = 1e-;
const int INF = << ;
const int dir[][] = {,,,,,-,-,};
const double pi = 3.1415926535898;
int T, n, m, cases;
int tree[maxn][maxn][maxn];
int a[maxn][maxn][maxn];
int lowbit(int x)
{
return x&(-x);
}
int sum(int x, int y, int z)
{
int ans = ;
for(int i = x; i <= n; i += lowbit(i))
for(int j = y; j <= n; j += lowbit(j))
for(int k = z; k <= n; k += lowbit(k))
ans += tree[i][j][k];
return ans;
}
void add(int x, int y, int z, int d)
{
for(int i = x; i > ; i -= lowbit(i))
for(int j = y; j > ; j -= lowbit(j))
for(int k = z; k > ; k -= lowbit(k))
tree[i][j][k] += d;
}
int main()
{
while(cin >> n >> m)
{
MEM(tree, );
MEM(a, );
int t, x1, y1, z1, x2, y2, z2;
while(m--)
{
scanf("%d", &t);
if(t)
{
scanf("%d%d%d%d%d%d", &x1, &y1, &z1, &x2, &y2, &z2);
add(x2, y2, z2, );
add(x2, y1 - , z2, );
add(x1 - , y2, z2, );
add(x2, y2, z1 - , );
add(x1 - , y1 - , z2, );
add(x1 - , y2, z1 - , );
add(x2, y1 - , z1 - , );
add(x1 - , y1 - , z1 - , );
}
else
{
scanf("%d%d%d", &x1, &y1, &z1);
cout<<(sum(x1, y1, z1)&)<<endl;
}
}
}
return ;
}

hdu-3584 Cube---三维树状数组+区域更新单点查询的更多相关文章

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

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

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

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

  3. POJ-2155 Matrix---二维树状数组+区域更新单点查询

    题目链接: https://vjudge.net/problem/POJ-2155 题目大意: 给一个n*n的01矩阵,然后有两种操作(m次)C x1 y1 x2 y2是把这个小矩形内所有数字异或一遍 ...

  4. 【poj2155】Matrix(二维树状数组区间更新+单点查询)

    Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...

  5. HDU 4031 Attack(线段树/树状数组区间更新单点查询+暴力)

    Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Sub ...

  6. NBOJv2 1050 Just Go(线段树/树状数组区间更新单点查询)

    Problem 1050: Just Go Time Limits:  3000 MS   Memory Limits:  65536 KB 64-bit interger IO format:  % ...

  7. hdu1556 树状数组区间更新单点查询板子

    就是裸的区间更新: 相对于直观的线段树的区间更新,树状数组的区间更新原理不太相同:由于数组中的一个结点控制的是一块区间,当遇到更新[l,r]时,先将所有能控制到 l 的结点给更新了,这样一来就是一下子 ...

  8. hdu3966 树链剖分点权模板+线段树区间更新/树状数组区间更新单点查询

    点权树的模板题,另外发现树状数组也是可以区间更新的.. 注意在对链进行操作时方向不要搞错 线段树版本 #include<bits/stdc++.h> using namespace std ...

  9. HDU 1556 Color the ball (树状数组 区间更新+单点查询)

    题目链接 Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽&quo ...

随机推荐

  1. EXCEL 导入SQL SERVER 方法

    1.注意:确认是否已安装 AccessDatabaseEngine.exe 2.可视化按提示操作.

  2. GC:并行回收CMS详解

    CMS详解 https://www.cnblogs.com/ggjucheng/p/3977612.html CMS默认不回收Perm, 需要加参数 +CMSPermGenSweepingEnable ...

  3. Launch iCar Scan Android Scanner Support Bluetooth X431 iDiag Update Version

    Autonumen.com release new Launch iCar Scan for Android,Launch iCarScan Bluetooth Scanner is update v ...

  4. Spring注入的反射解释

    对于如下配置片段:  <bean id="id" class="lee.Aclass">  <!--property配置需要依赖注入的属性-- ...

  5. python 层次索引交换级别以及排序问题

  6. RTT之AT命令组件

    包含客户端和服务器:用于GPRS和3G的通讯命令格式.四种基本功能 测试功能:AT+<x>=? 用于查询命令参数格式及取值范围: 查询功能:AT+<x>? 用于返回命令参数当前 ...

  7. Murano Application

    OpenStack Application Link: http://apps.openstack.org/ Those applications include Murano packages, H ...

  8. 贪心:钱币找零问题(C++)

    贪心是一种算法范例,它一点一点地构建解决方案,总是选择下一个提供最明显和最直接好处的部分.因此,选择局部最优也会导致全局解的问题最适合贪心问题. 例如,考虑分数背包问题.局部最优策略是选择权重比最大的 ...

  9. rails 里js 在production 只合并不压缩等问题,以及assets pipeline 加载js 在指定页面上

    因为刚学rails,试着做了一个小系统操作微信公共帐号, 之后部署的时候遇见了一个问题,整套系统在互联网端访问,非常的慢,而在手机端访问,10s后才会有响应, 打开chrome的调试工具,发现appl ...

  10. Kudu版本升级(官网推荐的步骤)(Upgrade from a Previous Version of Kudu)

    不多说,直接上干货! http://kudu.apache.org/docs/installation.html#sles_from_source