hdu-2642 Stars---二维树状数组(细节处理)
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2642
题目大意:
B x y:将星星x y点亮
D x y:将星星x y熄灭
Q x1 x2 y1 y2:询问该区域内有多少亮的星
解题思路:
二维树状数组模拟即可
注意:
1、下标+1
2、同一位置星星可以点亮多次,熄灭多次,需要用bool数组记录星星状态再更改树状数组
3、输入的区域是x1 x2 y1 y2,一开始错认为是x1 y1 x2 y2,而且没有大小顺序,需要自己判断
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
#include<vector>
#include<sstream>
#define lowbit(i) (i&(-i))
using namespace std;
int star[][];
bool light[][]; void add(int x, int y, int d)
{
for(int i = x; i <= ; i += lowbit(i))
{
for(int j = y; j <= ; j += lowbit(j))
star[i][j] += d;
}
}
int sum(int x, int y)
{
int ans = ;
for(int i = x; i; i -= lowbit(i))
{
for(int j = y; j; j -= lowbit(j))
ans += star[i][j];
}
return ans;
}
int main()
{
int n, x, y, x1, x2, y1, y2;
while(scanf("%d", &n) != EOF)
{
memset(light, , sizeof(light));
memset(star, , sizeof(star));
char c[];
while(n--)
{
scanf("%s", c);
if(c[] == 'B')
{
scanf("%d%d", &x, &y);
x++, y++;
if(!light[x][y])add(x, y, );
light[x][y] = ;
}
else if(c[] == 'D')
{
scanf("%d%d", &x, &y);
x++, y++;
if(light[x][y])add(x, y, -);
light[x][y] = ;
}
else if(c[] == 'Q')
{
scanf("%d%d%d%d", &x1, &x2, &y1, &y2);
x1++, y1++, x2++, y2++;
if(x1 > x2)swap(x1, x2);
if(y1 > y2)swap(y1, y2);
cout<<(sum(x2, y2) + sum(x1 - , y1 - ) - sum(x1 - , y2) - sum(x2, y1 - ))<<endl;
}
}
}
return ;
}
hdu-2642 Stars---二维树状数组(细节处理)的更多相关文章
- hdu 5517 Triple(二维树状数组)
Triple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- HDU 5517---Triple(二维树状数组)
题目链接 Problem Description Given the finite multi-set A of n pairs of integers, an another finite mult ...
- HDU 5517 【二维树状数组///三维偏序问题】
题目链接:[http://acm.split.hdu.edu.cn/showproblem.php?pid=5517] 题意:定义multi_set A<a , d>,B<c , d ...
- HDU 4456(二维树状数组+坐标转换)
题目链接:Problem - 4456 看别人叙述看的心烦,于是我自己画了一张图. 上图. 上代码 #include <iostream> #include <cstdio> ...
- hdu 2642 二维树状数组 单点更新区间查询 模板水题
Stars Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Subm ...
- hdu 2642二维树状数组 单点更新区间查询 模板题
二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html #include<stdio.h> #include& ...
- Stars(二维树状数组)
Stars Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Submiss ...
- 【 HDU - 4456 】Crowd (二维树状数组、cdq分治)
BUPT2017 wintertraining(15) #5A HDU 4456 题意 给你一个n行n列的格子,一开始每个格子值都是0.有M个操作,p=1为第一种操作,给格子(x,y)增加z.p=2为 ...
- HDU 5465 Clarke and puzzle Nim游戏+二维树状数组
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 26 ...
- HDU1559 最大子矩阵 (二维树状数组)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1559 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others) ...
随机推荐
- oracle 用mybatis生成主键
oracle主键是不能像mysql一样自动管理的,需要自己手动管理,先生成,再插入. <selectKey keyProperty="id" resultType=" ...
- robotframework 常用快捷键
重命名——>F2 执行用例——>F8 创建新工程——>ctrl+n 创建新测试套——>ctrl+shift+f 创建新用例——>ctrl+shift+t 创建新关键字—— ...
- 数据结构---Java---有序数组
[自定义有序数组] 查找算法: 线性查找算法:依次对比查询: 二分查找算法:必须是有序: insert:要插入的value与数组中每个元素进行比较,当有值>value时,此处的index之后的元 ...
- inventor怎样卸载干净
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...
- maya2016安装失败如何卸载重装
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...
- 为什么CPU缓存会分为一级缓存L1、L2、L3?有什么意义?
https://baijiahao.baidu.com/s?id=1598811284058671259&wfr=spider&for=pc 简介:CPU缓存是CPU一个重要的组成部分 ...
- python函数(四)
一.函数是什么? 函数一词来源于数学,但编程中的「函数」概念,与数学中的函数是有很大不同的,编程中的函数在英文中也有很多不同的叫法.在BASIC中叫做subroutine(子过程或子程序),在Pasc ...
- SolrCloud的搭建的连接
1 什么是SolrCloud SolrCloud(solr 云)是Solr提供的分布式搜索方案,当你需要大规模,容错,分布式索引和检索能力时使用SolrCloud.当一个系统的索引数据量少的时候是不需 ...
- Dedecms当前位置(面包屑导航)的处理
一.修改{dede:field name='position'/}的文字间隔符,官方默认的是> 在include/typelink.class.php第101行左右将>修改为你想要的符号即 ...
- java 正则表达式提取价格
实例代码: public static void main(String[] args) { String str="11000.00元"; Pattern pattern = P ...