题目链接:

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. oracle截取字符串,定索引

    转载:https://www.cnblogs.com/qmfsun/p/4493918.html 使用Oracle中Instr()和substr()函数: 1 2 3 4 5 6 7 8 9 10 1 ...

  2. mc01_IntelliJ IDEA安装与Java项目创建以及Tomcat配置

    IntelliJ IDEA安装与激活 下载地址:http://www.jetbrains.com/idea/ 安装下一步下一步即可,关键是注册激活,该部分分两个步骤: 1. 配置windows hos ...

  3. 异地clone RAC数据库 +ASM USE RMAN

    ###sample 如何在本地生成数据库的备份,并复制到DG库新环境(高级) 1. 首先确定本地文件系统(存放备份集)足够大,可以使用如下语句查询当前数据库实际的使用总大小 Rman 备份进度: se ...

  4. vue环境搭建(一)

    1.Vue依赖node npm命令执行,需要下载node 下载地址 2.安装全局vue-cli脚手架(搭建环境所需要模板),  window+ r 打开命令工具,输入cmd  ,这时显示命令行工具,输 ...

  5. c++中赋值运算符重载为什么要用引用做返回值?

    class string{ public: string(const char *str=NULL); string(const string& str);     //copy构造函数的参数 ...

  6. oracle_expdp_help

    [oracle@ctp ~]$ expdp -help Export: Release 11.2.0.3.0 - Production on Thu Feb 28 13:52:15 2019 Copy ...

  7. The Falling Leaves UVA - 699

    题目链接:https://vjudge.net/problem/UVA-699 题目大意:给一颗二叉树,每个结点都有一个水平位置 :左子节点在它左边的1个单位,右子结点在它右边1个单位.从左向右输出每 ...

  8. ssh RSA key变化后处理

    root@localhost:/# scp -r root@172.19.47.30:/home/linux-4.16.2-devm.1.2.aarch64.dongbo ./@@@@@@@@@@@@ ...

  9. [转]HTML字符实体(Character Entities),转义字符串(Escape Sequence)

    为什么要用转义字符串? HTML中<,>,&等有特殊含义(<,>,用于链接签,&用于转义),不能直接使用.这些符号是不显示在我们最终看到的网页里的,那如果我们希 ...

  10. (转)轻松应对IDC机房带宽突然暴涨问题

    原文:http://blog.51cto.com/oldboy/909696