题目链接:

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---二维树状数组(细节处理)的更多相关文章

  1. hdu 5517 Triple(二维树状数组)

    Triple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  2. HDU 5517---Triple(二维树状数组)

    题目链接 Problem Description Given the finite multi-set A of n pairs of integers, an another finite mult ...

  3. HDU 5517 【二维树状数组///三维偏序问题】

    题目链接:[http://acm.split.hdu.edu.cn/showproblem.php?pid=5517] 题意:定义multi_set A<a , d>,B<c , d ...

  4. HDU 4456(二维树状数组+坐标转换)

    题目链接:Problem - 4456 看别人叙述看的心烦,于是我自己画了一张图. 上图. 上代码 #include <iostream> #include <cstdio> ...

  5. hdu 2642 二维树状数组 单点更新区间查询 模板水题

    Stars Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others) Total Subm ...

  6. hdu 2642二维树状数组 单点更新区间查询 模板题

    二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html #include<stdio.h> #include& ...

  7. Stars(二维树状数组)

    Stars Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Submiss ...

  8. 【 HDU - 4456 】Crowd (二维树状数组、cdq分治)

    BUPT2017 wintertraining(15) #5A HDU 4456 题意 给你一个n行n列的格子,一开始每个格子值都是0.有M个操作,p=1为第一种操作,给格子(x,y)增加z.p=2为 ...

  9. HDU 5465 Clarke and puzzle Nim游戏+二维树状数组

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle  Accepts: 42  Submissions: 26 ...

  10. HDU1559 最大子矩阵 (二维树状数组)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1559 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others)  ...

随机推荐

  1. sshd服务及系统文件传输

    一.sshd 简介 sshd= secure shell 可以通过网络在主机中开机shell的服务 客户端软件 sshd 连接方式: ssh username@ip          ##文本模式的链 ...

  2. Rabbitmq相关学习网址

    1.安装文档: http://www.cnblogs.com/shuzhenyu/p/9823324.html 2.RabbitMq的整理 exchange.route.queue关系 https:/ ...

  3. MessageFormat 格式化String

    public static String buildFailureString(AtomicInteger count, String cause) { return MessageFormat.fo ...

  4. Linux链接器脚本详解

    /* GNU linker script for STM32F405 */ /* Specify the memory areas */ MEMORY { FLASH (rx) : ORIGIN = ...

  5. 爬虫(POST)——有道翻译(有bug)

    工具:python3 过程:抓包得到有道翻页面的url:复制post请求头,得到headers中的信息:复制post请求的body,得到formdata中的信息.构造post请求,返回响应 impor ...

  6. c++11 move构造函数和move operator 函数 学习

    先看个代码吧!!!!!!!!!! #include <iostream> using namespace std; class A { public: A(){cout<<&q ...

  7. B-树 B+树 红黑树

    B树是一种多路平衡查找树,它的每一个节点最多包含k个孩子,k被称为B树的阶.k的大小取决于磁盘页的大小.B树主要应用于文件系统以及部分数据库索引,比如著名的非关系型数据库MongoDB.一个m阶的B树 ...

  8. Java基本语法_循环练习系列(一)——模拟双色球

    目前正在自学java中,学完循环这一块,简单写几个例子,使之更加熟练掌握循环语句和条件语句. 简述一下要这段代码要完成的任务: /*有33个红色球,16个蓝色球. 在33个里选6个 ,16个里选1个. ...

  9. Win2D 官方文章系列翻译 - 调整控件分辨率

    本文为个人博客备份文章,原文地址: http://validvoid.net/win2d-choosing-control-resolution/ 本文旨在讲解如何配置 Win2D XAML 控件使用 ...

  10. SSRS 参数 单选 多选

    前段时间 公司要求报表的选项可以多选. 知道需求后,研究了下实现. 首先我们创建一个报表,然后添加3个数据集,2个参数,如下图. DataSet1数据集:存放主数据. ddl_emplid数据集:存放 ...