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. arm+linux 裸机环境搭建之初试minicom+dnw烧写uboot

    下面的步骤将会实现在linux下面使用dnw+minicom来烧写uboot 一.安装minicom 下载地址:http://download.csdn.net/detail/king_bingge/ ...

  2. 安装hadoop2.6.0伪分布式环境

    集群环境搭建请见:http://blog.csdn.net/jediael_lu/article/details/45145767 一.环境准备 1.安装linux.jdk 2.下载hadoop2.6 ...

  3. jquery1.9学习笔记 之选择器(基本元素三)

    标签选择器("element") 描述: 选择所有与给出标签名相匹配的元素. 同功能的JS原生方法:getElementByTagName() 例子:  查找每个div元素. &l ...

  4. 神奇的match和replace

    源自跟奈落大叔的讨论,PHP和JavaScript的比较. 正则: 先说几个正则写法: () 选择匹配一组, (?:) 降低 () 的优先级, .*? 和 .+? ,阻止 . 和 + 的贪婪. 还有一 ...

  5. DNS预获取(dns-prefetch)

    今天翻看twitter的源码的时候看到了一下内容: <link rel=”dns-prefetch” href=”http://a0.twimg.com”/> <link rel=” ...

  6. Xcode6中自动布局autolayout和sizeclass的使用

    Xcode6中自动布局autolayout和sizeclass的使用   一.关于自动布局(Autolayout) 在Xcode中,自动布局看似是一个很复杂的系统,在真正使用它之前,我也是这么认为的, ...

  7. C++类的数组元素查找最大值问题

    找出一个整型数组中的元素的最大值. /*找出一个整型数组中的元素的最大值.*/ #include <iostream> using namespace std; class ArrayMa ...

  8. ServletContext对象(每个工程只有一个此对象)

    一]重点方法:        1>存取对象                        void setAttribute(String name, Object object);//将obj ...

  9. Awesome Go

    A curated list of awesome Go frameworks, libraries and software. Inspired by awesome-python. Contrib ...

  10. dedecms 在php7.0无法安装

    dedecms 需要mysql扩展的支持!而php7.0已废弃mysql扩展.所以我讲7.0改回了5.6然后就可以顺利安装了. 总结了一个经验:没有绝对实力,不要尝试新东西