See you~

Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 6520    Accepted Submission(s): 2040

Problem Description
Now I am leaving hust acm. In the past two and half years, I learned so many knowledge about Algorithm and Programming, and I met so many good friends. I want to say sorry to Mr, Yin, I must leave now ~~>.<~~. I am very sorry, we could not advanced to the World Finals last year. 
When coming into our training room, a lot of books are in my eyes. And every time the books are moving from one place to another one. Now give you the position of the books at the early of the day. And the moving information of the books the day, your work is to tell me how many books are stayed in some rectangles. 
To make the problem easier, we divide the room into different grids and a book can only stayed in one grid. The length and the width of the room are less than 1000. I can move one book from one position to another position, take away one book from a position or bring in one book and put it on one position. 
 
Input
In the first line of the input file there is an Integer T(1<=T<=10), which means the number of test cases in the input file. Then N test cases are followed. 
For each test case, in the first line there is an Integer Q(1<Q<=100,000), means the queries of the case. Then followed by Q queries. 
There are 4 kind of queries, sum, add, delete and move. 
For example: 
S x1 y1 x2 y2 means you should tell me the total books of the rectangle used (x1,y1)-(x2,y2) as the diagonal, including the two points. 
A x1 y1 n1 means I put n1 books on the position (x1,y1) 
D x1 y1 n1 means I move away n1 books on the position (x1,y1), if less than n1 books at that position, move away all of them. 
M x1 y1 x2 y2 n1 means you move n1 books from (x1,y1) to (x2,y2), if less than n1 books at that position, move away all of them. 
Make sure that at first, there is one book on every grid and 0<=x1,y1,x2,y2<=1000,1<=n1<=100. 
 
Output
At the beginning of each case, output "Case X:" where X is the index of the test case, then followed by the "S" queries. 
For each "S" query, just print out the total number of books in that area. 
 
Sample Input
2
3
S 1 1 1 1
A 1 1 2
S 1 1 1 1
3
S 1 1 1 1
A 1 1 2
S 1 1 1 2
 
Sample Output
Case 1:
1
3
Case 2:
1
4
 
Author
Sempr|CrazyBird|hust07p43
 
Source
  
  二维BIT的模板题,注意S时给出的两个点要自己转换一下保证一个是左上角一个是右下角。
 二维的BIT里面的每个节点是一个矩阵,宽度就是x的lowbit,长度就是y的lowbit,右下角就是(X,Y)。
  

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ULL unsigned long long
  4. #define LL long long
  5. LL C[][];
  6. int A[][];
  7. inline int lowbit(int x){return x&-x;}
  8. void add(int x,int y,int d){
  9. for(int i=x;i<=;i+=lowbit(i))
  10. for(int j=y;j<=;j+=lowbit(j))
  11. C[i][j]+=d;
  12. }
  13. LL sum(int x,int y){
  14. LL r=;
  15. for(int i=x;i>;i-=lowbit(i))
  16. for(int j=y;j>;j-=lowbit(j))
  17. r+=C[i][j];
  18. return r;
  19. }
  20. int main(){
  21. int t,x1,x2,y1,y2,n,q,cas=;
  22. char ch[];
  23. scanf("%d",&t);
  24. while(t--){
  25. memset(C,,sizeof(C));
  26. for(int i=;i<=;++i)
  27. for(int j=;j<=;++j) add(i,j,),A[i][j]=;
  28. scanf("%d",&q);
  29. printf("Case %d:\n",++cas);
  30. while(q--){
  31. scanf("%s",ch);
  32. if(ch[]=='S'){
  33. scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
  34. x1++,y1++,x2++,y2++;
  35. if(x1>x2) swap(x1,x2);
  36. if(y1>y2) swap(y1,y2);
  37. printf("%lld\n",sum(x2,y2)-sum(x1-,y2)-sum(x2,y1-)+sum(x1-,y1-));
  38. }
  39. else if(ch[]=='A'){
  40. scanf("%d%d%d",&x1,&y1,&n);
  41. x1++,y1++;
  42. add(x1,y1,n);
  43. A[x1][y1]+=n;
  44. }
  45. else if(ch[]=='D'){
  46. scanf("%d%d%d",&x1,&y1,&n);
  47. x1++,y1++;
  48. n=min(n,A[x1][y1]);
  49. add(x1,y1,-n);
  50. A[x1][y1]-=n;
  51. }
  52. else if(ch[]=='M'){
  53. scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&n);
  54. x1++,y1++,x2++,y2++;
  55. n=min(n,A[x1][y1]);
  56. add(x1,y1,-n),A[x1][y1]-=n;
  57. add(x2,y2,n),A[x2][y2]+=n;
  58. }
  59. }
  60. }
  61. return ;
  62. }
 

hdu-1892-二维BIT的更多相关文章

  1. HDU 2159 二维费用背包问题

    一个关于打怪升级的算法问题.. 题意:一个人在玩游戏老是要打怪升级,他愤怒了,现在,还差n经验升级,还有m的耐心度(为零就删游戏不玩了..),有m种怪,有一个最大的杀怪数s(杀超过m只也会删游戏的.. ...

  2. hdu 4819 二维线段树模板

    /* HDU 4819 Mosaic 题意:查询某个矩形内的最大最小值, 修改矩形内某点的值为该矩形(Mi+MA)/2; 二维线段树模板: 区间最值,单点更新. */ #include<bits ...

  3. F - F HDU - 1173(二维化一维-思维)

    F - F HDU - 1173 一个邮递员每次只能从邮局拿走一封信送信.在一个二维的直角坐标系中,邮递员只能朝四个方向移动,正北.正东.正南.正西. 有n个需要收信的地址,现在需要你帮助找到一个地方 ...

  4. HDU 3496 (二维费用的01背包) Watch The Movie

    多多想看N个动画片,她对这些动画片有不同喜欢程度,而且播放时长也不同 她的舅舅只能给她买其中M个(不多不少恰好M个),问在限定时间内观看动画片,她能得到的最大价值是多少 如果她不能在限定时间内看完买回 ...

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

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

  6. hdu 2888 二维RMQ模板题

    Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  7. Coconuts HDU - 5925 二维离散化 自闭了

    TanBig, a friend of Mr. Frog, likes eating very much, so he always has dreams about eating. One day, ...

  8. HDU 1263 二维map

    题意:给出一份水果的交易表,根据地区统计出水果的交易情况.   思路:二维map使用.   #include<cstdio> #include<string> #include ...

  9. hdu 2888 二维RMQ

    Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

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

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

随机推荐

  1. 看阿里P9架构师如何向你定义架构及架构师

    架构的定义 先来看看软件架构的普遍定义吧. 一个程序和计算系统软件体系结构是指系统的一个或多个结构.结构中包括软件的构建,构建的外部可见属性以及它们之间的相互关系. 体系结构并非可运行软件.确切的说, ...

  2. 20145317彭垚_Web基础

    20145317彭垚_Web基础 基础知识 Apache一个开放源码的网页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一.它快速.可靠并且可 ...

  3. 《网络对抗》——逆向及Bof基础实践

    <网络对抗>--逆向及Bof基础实践 原理 利用foo函数的Bof漏洞,构造一个攻击输入字符串,覆盖返回地址,触发getShell函数. 手工修改可执行文件,改变程序执行流程,直接跳转到g ...

  4. Beetl模板引擎入门教程

    最近项目中有个邮件发送的需求,不过要求发送的HTML格式的邮件.由于Beetl对java语言的良好支持和很好的性能,我们决定使用Beetl作为我们的模板引擎. Beetl官网已经有了很详细的教程,所以 ...

  5. Eclipse的快捷键使用总结

    最近一直在使用Idea开发项目,导致之前一直使用的Eclipse快捷键忘记的差不多了,现在稍微整理了一些,方便以后可以快速切换回来. 常用的Eclipse快捷键总结: Ctrl+S 保存当前正在编辑的 ...

  6. rvm 安装ruby环境报错curl: (35) error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure

    很可能是rvm仓库版本过低,运行以下命令: rvm get head

  7. SxsTrace

    https://troubleshooter.xyz/wiki/fix-the-application-has-failed-to-start-because-the-side-by-side-con ...

  8. 51nod 1051 最大子矩阵和

    没想到居然可以O(n3)暴力过 就是大概之前的  最大连续子序列和 加成2维度了  枚举起始列 和 终止列 然后计算从1到n行最大的子矩阵的和 注意n 和 m 的输入顺序!! #include< ...

  9. Sass常用写法

    Sass使用变量,变量以$开头 $bgcolor:#f40; background-color:$bgcolor; 如果变量需要嵌套在字符串当中,就需要写在#{}之中 $direction:left; ...

  10. 桌面共享UDP组播实现

    组播(Multicast)传输:在发送者和每一接收者之间实现点对多点网络连接.如果一台发送者同时给多个的接收者传输相同的数据,也只需复制一份的相同数据包.它提高了数据传送效率.减少了骨干网络出现拥塞的 ...