HDU 5892 Resident Evil(二维树状数组,好题)
来源:互联网 发布:淘宝买违禁品怎么查到 编辑:程序博客网 时间:2024/06/08 11:54
题目大意
这道题的大意是一个城市有n*n个格子组成,每次都可以选择一个长方形的区域然后往里面放怪物,然后这个长方形区域里面的每个小格子都有同样数量的怪物,就是相当于一个二维区间更新了,然后又给你一个长方形的区域,询问该长方形区域里面有多少50种怪物的具体情况,如果该种怪物为奇数则输出2,否则输出1.
题目分析
我们可以利用树状数组来完场区间更新,对于50种怪物很明显可以用long long类型进状态压缩,这也很好理解。如果我们放入怪物后,如果某种怪物为偶数那么不用更新,因为该种怪物的奇偶不会变,如果为奇数则需要更新。。更新时我们会发现,如果该位置为x,则对于树状数组而言与x奇偶性相同的会受到影响,奇偶性不同的不会受到影响,因为前缀和的思想,奇偶性不同就会更新2次,奇数+奇数一定为偶数,所以就很明显了。我们可以多开一维,只修改x奇偶性对应的那一维即可。
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 3005;#define LL long long#define lowbit(x) x&-xLL bit[2][2][maxn][maxn], devil[55];int n, m;void add(int x, int y, LL val){ for(int i = x; i <= n; i += lowbit(i)) for(int j = y; j <= n; j += lowbit(j)) bit[x&1][y&1][i][j] ^= val;}LL sum(int x, int y){ LL res = 0; for(int i = x; i > 0; i -= lowbit(i)) for(int j = y; j > 0; j -= lowbit(j)) res ^= bit[x&1][y&1][i][j]; return res;}int main(){ char op; while(scanf("%d%d", &n, &m) != EOF){ memset(bit, 0, sizeof(bit)); int x1, x2, y1, y2, a, b, k; while(m--){ scanf(" %c%d%d%d%d", &op, &x1, &y1, &x2, &y2); if(op == 'P'){ scanf("%d", &k); memset(devil, 0, sizeof(devil)); for(int i = 0; i < k; i++){ scanf("%d%d", &a, &b); devil[--a] += b; } LL temp = 0; for(int i = 0; i < 50; i++) if(devil[i]&1) temp |= (1LL<<i); y2++, x2++; add(x1, y1, temp); add(x1, y2, temp); add(x2, y1, temp); add(x2, y2, temp); } else{ x1--, y1--; LL temp = sum(x1, y1)^sum(x1, y2)^sum(x2, y1)^sum(x2, y2); for(int i = 0; i < 50; i++) if(temp&(1LL<<i)) printf("2 "); else printf("1 "); printf("\n"); } } } return 0;}
0 0
- HDU 5892 Resident Evil(二维树状数组,好题)
- [HDU 5892] Resident Evil (二维树状数组)
- 2016 ACM/ICPC Reginal Shengyang hdu 5892 -Resident Evil 二维树状数组 + 状态压缩
- HDU 5892 Resident Evil(状态压缩+树状数组)
- hdu5892 -Resident Evil 二维树状数组 + 状态压缩
- HDU5892 Resident Evil(二维树状数组+状态压缩)
- HDU5892Resident Evil(二维树状数组+状态压缩)
- HDU 1892 二维树状数组 模板题
- 二维树状数组 hdu 1892
- 【二维树状数组】HDU 1892
- HDU 1892 二维树状数组
- HDU 1892 二维树状数组
- HDU 2642 二维树状数组
- HDU 1892 (二维树状数组)
- HDU 1892 二维树状数组
- hdu 1892 二维树状数组
- hdu 2642 二维树状数组
- HDU 1892 二维树状数组
- 【u034】追查坏奶牛
- DS单链表--类实现
- VLOOKUP函数语法解析
- RunTime类
- python微信飞机大战
- HDU 5892 Resident Evil(二维树状数组,好题)
- 深入理解与应用Hadoop中的MapReduce
- 双缓冲技术
- ZooKeeper入门笔记---架构以及应用介绍
- 百度地图 ld: framework not found BaiduMapAPI_Location 或 高德地图 ld: framework not found AMapLocationKit
- 机器学习笔记——岭回归(Ridge Regression)
- 你自己的抑郁症体验
- 深入理解与应用Hadoop中的MapReduce
- 手机站拨打电话实现方式