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

二维树状数组

代码:

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstring>
  4. using namespace std;
  5. int a[1005][1005],c[1005][1005];
  6. int lowbit(int x)
  7. {
  8. return x&(-x);
  9. }
  10. int Sum(int i,int j)
  11. { int sum=0,k,p;
  12. for(k=i;k>0;k=k-lowbit(k))
  13. for(p=j;p>0;p=p-lowbit(p))
  14. sum+=c[k][p];
  15. return sum;
  16. }
  17. void change(int i,int j,int x)
  18. { int k,p;
  19. for(k=i;k<=1004;k=k+lowbit(k))
  20. for(p=j;p<=1004;p=p+lowbit(p))
  21. c[k][p]+=x;
  22. }
  23. int main()
  24. {
  25. int i,j,k,n,m,x,y;
  26. char ch;
  27. while(cin>>n)
  28. {
  29. m=n;
  30. memset(a,0,sizeof(a));
  31. memset(c,0,sizeof(c));
  32. while(n--)
  33. {
  34. cin>>ch;
  35. if(ch=='B'||ch=='D')
  36. {
  37. cin>>x>>y;
  38. x++;y++;
  39. if(ch=='B'&&a[x][y]==0)
  40. {
  41. change(x,y,1);
  42. a[x][y]=1;
  43. }
  44.  
  45. if(ch=='D'&&a[x][y]==1)
  46. {
  47. change(x,y,-1);
  48. a[x][y]=0;
  49. }
  50. }
  51. else
  52. { int x1,x2,y1,y2;
  53. cin>>x1>>x2>>y1>>y2;
  54. if(x1>x2)
  55. swap(x1,x2);
  56.  
  57. if(y1>y2)
  58. swap(y1,y2);
  59. cout<<Sum(x2+1,y2+1)+Sum(x1,y1)-Sum(x1,y2+1)-Sum(x2+1,y1)<<endl;
  60. }
  61.  
  62. }
  63. }
  64. return 0;
  65. }

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. C/C++中字符串存储位置

    代码: #include <iostream> #include <cstdio> using namespace std; void fun(char **p){ //cha ...

  2. eclipse项目显示标尺

    Windows-Preferences-General-Editors-Text Editors-Show line numbers

  3. Thinkphp join 连接查询

    public function test ( ) { $User = M('authlist'); $rs = $User->join('left join wifi_shop on wifi_ ...

  4. lazy loading img 图片延迟加载

    http://yunpan.cn/cVsjPW6dgbcsh (提取码:b5db)

  5. 关于 VS2013监视窗口的内存面板及寄存器面板

    1.插入断点,按F5调试,2.选择菜单项 debug-窗口-3.即可找到您要的监视窗口.

  6. ubuntu soft install

    1.Mysql 安装就三个命令 mysql服务端 sudo apt-get install mysql-server mysql客户端 sudo apt-get install mysql-clien ...

  7. Robot Framework自动化测试环境的搭建

    1.python-2.7.6.amd64.1394777203.msi 2.setuptools-28.0.0 3.pip-8.1.1 4.robotframework-2.8.7.win-amd64 ...

  8. Leakcanary

    一.什么是内存泄漏 垃圾回收器无法回收应被回收的对象比如:在Activity生命周期过程中,旋转屏幕时应新建activity,原activity应被销毁.但如果线程一直在引用此activity,则会出 ...

  9. android开发3:四大基本组件的介绍与生命周期

    android开发3:四大基本组件的介绍与生命周期 Android四大基本组件分别是Activity,Service服务,Content Provider内容提供者,BroadcastReceiver ...

  10. 伟福与Keil的比较--51汇编提高篇

    [写在前面] 本文适合有一定汇编水平的人(了解大半的汇编语句,能区分全角与半角符号,能够独立编写流水灯.数码管等程序),传授51单片机的汇编语言经验.如果您发现不少指令不知道意思,请从网上搜索入门教程 ...