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)。
  

 #include<bits/stdc++.h>
using namespace std;
#define ULL unsigned long long
#define LL long long
LL C[][];
int A[][];
inline int lowbit(int x){return x&-x;}
void add(int x,int y,int d){
for(int i=x;i<=;i+=lowbit(i))
for(int j=y;j<=;j+=lowbit(j))
C[i][j]+=d;
}
LL sum(int x,int y){
LL r=;
for(int i=x;i>;i-=lowbit(i))
for(int j=y;j>;j-=lowbit(j))
r+=C[i][j];
return r;
}
int main(){
int t,x1,x2,y1,y2,n,q,cas=;
char ch[];
scanf("%d",&t);
while(t--){
memset(C,,sizeof(C));
for(int i=;i<=;++i)
for(int j=;j<=;++j) add(i,j,),A[i][j]=;
scanf("%d",&q);
printf("Case %d:\n",++cas);
while(q--){
scanf("%s",ch);
if(ch[]=='S'){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
x1++,y1++,x2++,y2++;
if(x1>x2) swap(x1,x2);
if(y1>y2) swap(y1,y2);
printf("%lld\n",sum(x2,y2)-sum(x1-,y2)-sum(x2,y1-)+sum(x1-,y1-));
}
else if(ch[]=='A'){
scanf("%d%d%d",&x1,&y1,&n);
x1++,y1++;
add(x1,y1,n);
A[x1][y1]+=n;
}
else if(ch[]=='D'){
scanf("%d%d%d",&x1,&y1,&n);
x1++,y1++;
n=min(n,A[x1][y1]);
add(x1,y1,-n);
A[x1][y1]-=n;
}
else if(ch[]=='M'){
scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&n);
x1++,y1++,x2++,y2++;
n=min(n,A[x1][y1]);
add(x1,y1,-n),A[x1][y1]-=n;
add(x2,y2,n),A[x2][y2]+=n;
}
}
}
return ;
}
 

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. Ubuntu系统下Jenkins的本地构建基本方法

    上一篇文章介绍了,jenkins的安装和系统配置之后,配置登录成功后,就可以新建jenkins构建项目,用于自动化构建. 1.项目名称和项目描述 点击左上角的 新建任务,输入项目名称,选择 构建一个自 ...

  2. web前端----css选择器样式

    一.css概述 CSS是Cascading Style Sheets的简称,中文称为层叠样式表,对html标签的渲染和布局 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. 例如 二.c ...

  3. P2486 [SDOI2011]染色

    P2486 [SDOI2011]染色 树链剖分 用区间修改线段树维护 对于颜色段的计算:sum[o]=sum[lc]+sum[rc] 因为可能重复计算,即左子树的右端点和右子树的左端点可能颜色相同 多 ...

  4. 关键字union

    union有一个作用就是判断,pc是大端存储还是小端存储的,x86是小端存储的,这个东西是有cpu决定的.arm(由存储器控制器决定)和x86一样都是小端的. 下面的是一个大端小端的一个例子,代码如下 ...

  5. BZOJ2819: Nim 树链剖分

    Description 著名游戏设计师vfleaking,最近迷上了Nim.普通的Nim游戏为:两个人进行游戏,N堆石子,每回合可以取其中某一堆的任意多个,可以取完,但不可以不取.谁不能取谁输.这个游 ...

  6. java自学入门心得体会 0.1

    之前记录了java的简介和基本语法 这里记载下对象和类 不太懂的我理解java对象和类的概念很模糊,因为有了 Abstract修饰符 让对象与类更加的扑朔迷离 - - 所以,就像很开放的语言,创建对象 ...

  7. 项目梳理6——使用WebApiTestClient为webapi添加测试

    1.使用nuget添加WebApiTestClient的引用 2.xxxxx.WebApi\Areas\HelpPage\Views\Help\Api.cshtml页面末尾添加如下代码: @Html. ...

  8. 【TCP/IP详解 卷一:协议】第十二章 广播和多播

    建议参考:广播和多播 IGMP 12.1 引言 IP地址知识点回顾: IP地址分为三种:(1)单播地址 (2)广播地址 (3)多播地址 另外一种是,IP地址一般划分成五类:A-E类. 单播 考虑 类似 ...

  9. Java中引用的详解

    Java中没有指针,到处都是引用(除了基本类型).所以,当然,你肯定知道java的引用,并用了很久,但是是不是对此了解地比较全面?而这些引用有什么作用,且有什么不同呢?Java中有个java.lang ...

  10. C#完美读取CSV

    /// <summary>         /// 将DataTable中数据写入到CSV文件中         /// </summary>         /// < ...