Problem Description

Yifenfei is a romantic guy and he likes to count the stars in the sky.

To make the problem easier,we considerate the sky is a two-dimension plane.Sometimes the star will be bright and sometimes the star will be dim.At first,there is no bright star in the sky,then some information will be given as "B x y" where 'B' represent bright
and x represent the X coordinate and y represent the Y coordinate means the star at (x,y) is bright,And the 'D' in "D x y" mean the star at(x,y) is dim.When get a query as "Q X1 X2 Y1 Y2",you should tell Yifenfei how many bright stars there are in the region
correspond X1,X2,Y1,Y2.



There is only one case.





Input

The first line contain a M(M <= 100000), then M line followed.

each line start with a operational character.

if the character is B or D,then two integer X,Y (0 <=X,Y<= 1000)followed.

if the character is Q then four integer X1,X2,Y1,Y2(0 <=X1,X2,Y1,Y2<= 1000) followed.





Output

For each query,output the number of bright stars in one line.





Sample Input

5

B 581 145

B 581 145

Q 0 600 0 200

D 581 145

Q 0 600 0 200





Sample Output

1

0

二维树状数组

代码:

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int a[1005][1005],c[1005][1005];
int lowbit(int x)
{
return x&(-x);
}
int Sum(int i,int j)
{ int sum=0,k,p;
for(k=i;k>0;k=k-lowbit(k))
for(p=j;p>0;p=p-lowbit(p))
sum+=c[k][p];
return sum;
}
void change(int i,int j,int x)
{ int k,p;
for(k=i;k<=1004;k=k+lowbit(k))
for(p=j;p<=1004;p=p+lowbit(p))
c[k][p]+=x;
}
int main()
{
int i,j,k,n,m,x,y;
char ch;
while(cin>>n)
{
m=n;
memset(a,0,sizeof(a));
memset(c,0,sizeof(c));
while(n--)
{
cin>>ch;
if(ch=='B'||ch=='D')
{
cin>>x>>y;
x++;y++;
if(ch=='B'&&a[x][y]==0)
{
change(x,y,1);
a[x][y]=1;
} if(ch=='D'&&a[x][y]==1)
{
change(x,y,-1);
a[x][y]=0;
}
}
else
{ int x1,x2,y1,y2;
cin>>x1>>x2>>y1>>y2;
if(x1>x2)
swap(x1,x2); if(y1>y2)
swap(y1,y2);
cout<<Sum(x2+1,y2+1)+Sum(x1,y1)-Sum(x1,y2+1)-Sum(x2+1,y1)<<endl;
} }
}
return 0;
}

hdu 2642 Stars的更多相关文章

  1. hdu 2642 Stars 【二维树状数组】

    题目 题目大意:Yifenfei是一个浪漫的人,他喜欢数天上的星星.为了使问题变得更容易,我们假设天空是一个二维平面,上面的星星有时会亮,有时会发暗.最开始,没有明亮的星星在天空中,然后将给出一些信息 ...

  2. hdu 1541 Stars

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 思路:要求求出不同等级的星星的个数,开始怎么也想不到用树状数组,看完某些大神的博客之后才用树状数 ...

  3. POJ 2352 Stars(HDU 1541 Stars)

    Stars Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41521   Accepted: 18100 Descripti ...

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

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

  5. HDU 1541 Stars (树状数组)

    Problem Description Astronomers often examine star maps where stars are represented by points on a p ...

  6. POJ 2352 &amp;&amp; HDU 1541 Stars (树状数组)

    一開始想,总感觉是DP,但是最后什么都没想到.还暴力的交了一发. 然后開始写线段树,结果超时.感觉自己线段树的写法有问题.改天再写.先把树状数组的写法贴出来吧. ~~~~~~~~~~~~~~~~~~~ ...

  7. hdu 5126 stars (四维偏序,离线,CDQ套CDQ套树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5126 思路:支持离线,那么我们可以用两次CDQ分治使四维降为二维,降成二维后排个序用树状数组维护下就好 ...

  8. HDU 1541 Stars (线段树)

     Problem Description Astronomers often examine star maps where stars are represented by points on ...

  9. HDU 1589 Stars Couple(计算几何求二维平面的最近点对和最远点对)

    Time Limit: 1000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

随机推荐

  1. 类 this指针 const成员函数

    C++ Primer 第07章 类 7.1.2 ​Sales_data类的定义如下: #ifndef SALES_DATA_H #define SALES_DATA_H #include <st ...

  2. event对象具有的方法

    // dataTransfer,toElement,fromElement,y,x,offsetY,offsetX,webkitMovementY,webkitMovementX,relatedTar ...

  3. mysql 主从搭建

    主要搭建步骤如下: 1.打开binlog,设置server_id     打开主库的--log-bin,并设置server_id 2.主库授权                --最好也在从库对主库授权 ...

  4. Bootstrap3 入门实战

    因为公司选择了使用BootStrap3作为项目的前台展示框架,所以花了半天时间来学习Bootstrap, 如果你是第一次听说,或者说以前听说过,但没有使用过这个框架的话,希望这篇入门实战能够让你快速掌 ...

  5. php 二维数组按照某value值求出最大值最小值

    //商家的等级信息是一个二维数组,求出最小折扣和最大折扣array(0=>array('levelname'=>'银','dis'=>7.5), 1=>array('level ...

  6. 让IE支持CSS3 Media Query实现响应式Web设计

    如今的屏幕分辨率,小至320px(iPhone),大到2560px甚至更高(大显示器),变化范围极大.除了使用传统的台式机,用户会越来越多的通过手机.上网本.iPad一类的平板设备来浏览页面.这种情况 ...

  7. C程序设计语言练习题1-5

    练习1-5 修改温度转换程序,要求以逆序(即按照从300度到0度的顺序)打印温度转换表. 代码如下: #include <stdio.h> // 包含标准库的信息. int main() ...

  8. SSH登陆错误 WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

    今天遇到问题,删除文件即搞定!! ~~~~~~~~~~~~~~ SSH登陆错误 WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!   Connectio ...

  9. python mysql curros.executemany 批量添加

    #添加的表结构字段分辨是(id,title,summary,visits,accountName,grabTime) #其中id,是int自增主键,在添加操作的时候,不需要对id进行操作 conn = ...

  10. python3-day5(模块)

    1.获取路径import os,sys #获取全部路径 print(os.path.abspath(__file__)) #获取目录 print(os.path.dirname(os.path.abs ...