题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1892

See you~

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

 /*AC代码*/
#include <cstdio>
#include <cstring>
#include <iostream> using namespace std; const int size = ;
int a[size+][size+]; int lowbit(int i)
{
return i & (-i);
} void add(int x, int y, int num)
{
for(int i = x; i <= size; i += lowbit(i))
for(int j = y; j <= size; j += lowbit(j))
a[i][j] += num;
} int getSum(int x, int y)
{
int tot = ;
for(int i = x; i > ; i -= lowbit(i))
for(int j = y; j > ; j -= lowbit(j))
tot += a[i][j];
return tot;
} void init()
{
memset(a, , sizeof(a));
for(int i = ; i < size; ++i)
for(int j = ; j < size; ++j)
add(i, j, );
} int main()
{
int T, n, x1, x2, y1, y2, n1;
char cmd[];
scanf("%d", &T);
for(int cnt = ; cnt <= T; ++cnt)
{
init();
scanf("%d", &n);
printf("Case %d:\n", cnt);
while(n--)
{
scanf("%s", cmd);
if(cmd[] == 'A')
{
scanf("%d%d%d", &x1, &y1, &n1);
add(x1+, y1+, n1);
}
else if(cmd[] == 'S')
{
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
++x1;
++x2;
++y1;
++y2;
if(x1 > x2)
swap(x1, x2);
if(y1 > y2)
swap(y1, y2);
int temp;
temp=getSum(x2,y2)-getSum(x1-,y2)-getSum(x2,y1-)+getSum(x1-,y1-);
printf("%d\n",temp);
}
else if(cmd[] == 'D')
{
scanf("%d%d%d",&x1,&y1,&n1);
++x1;
++y1;
int temp;
temp=getSum(x1,y1)-getSum(x1-,y1)-getSum(x1,y1-)+getSum(x1-,y1-);
if(n1 > temp)
n1 = temp;
add(x1, y1, -n1);
}
else if(cmd[] == 'M')
{
scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &n1);
++x1;
++x2;
++y1;
++y2;
int temp;
temp=getSum(x1,y1)-getSum(x1-,y1)-getSum(x1,y1-)+getSum(x1-,y1-);
if(n1 > temp)
n1 = temp;
add(x1, y1, -n1);
add(x2, y2, n1);
}
}
}
return ;
}

HDU 1892 See you~ (二维树状数组)的更多相关文章

  1. HDU 1892(书架统计 二维树状数组)

    题意是在二维平面上在一些位置上进行数据的增删改查操作,使用树状数组(了解树状数组点这里) 原来的树状数组在求区间和时是 sum( x, y ) = getsum( y ) - getsum( x - ...

  2. 【 HDU - 4456 】Crowd (二维树状数组、cdq分治)

    BUPT2017 wintertraining(15) #5A HDU 4456 题意 给你一个n行n列的格子,一开始每个格子值都是0.有M个操作,p=1为第一种操作,给格子(x,y)增加z.p=2为 ...

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

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

  4. hdu 5517 Triple(二维树状数组)

    Triple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  5. HDU 5517---Triple(二维树状数组)

    题目链接 Problem Description Given the finite multi-set A of n pairs of integers, an another finite mult ...

  6. HDU 5517 【二维树状数组///三维偏序问题】

    题目链接:[http://acm.split.hdu.edu.cn/showproblem.php?pid=5517] 题意:定义multi_set A<a , d>,B<c , d ...

  7. HDU 5465 Clarke and puzzle Nim游戏+二维树状数组

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle  Accepts: 42  Submissions: 26 ...

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

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

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

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

随机推荐

  1. Bootstrap学习------按钮

    Bootstrap为我们提供了按钮组的样式,博主写了几个简单的例子,以后也许用的到. 效果如下 代码如下 <!DOCTYPE html> <html> <head> ...

  2. 使用Entity Framework通过code first方式创建数据库和数据表

    开发环境 WIN10 Entity Framework6.0  MVC5.0  开发工具 VS2015  SqlServer2012 1.创建上下文Context继承DbContext,并创建其他的业 ...

  3. CentOS下安装JDK1.7

    1.安装包准备: 首先到官网下载jdk,http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.h ...

  4. redis cluster php 客户端 predis

    php有redis的扩展,目前来说,还不支持redis cluster,推荐一下predis,功能比较全,从单个,到主从,到cluster都是支持的.效率怎么样,要靠自己去测试一下. 1,下载pred ...

  5. Java实现JDBC连接数据库实例

    import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sq ...

  6. Angular2 组件

    1. 组件说明 Angular2 组件是构成Angular2应用程序的核心部分,Angualr2应用程序本质上来说就是一个组件树,Angular2组件一般由模块,注解,元数据以及组件类组成,实现组件类 ...

  7. ffmpeg-20160901-bin.7z

    ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 5 屏幕横向放大 20 像素 6 屏幕横向缩小 20 像素 S 下一帧 [ -2秒 ] +2 ...

  8. rpm 与 yum 源

    rpm rpm -e                删除软件包rpm -i                安装软件包rpm -U                更新软件包rpm -qa         ...

  9. 图片切换小demo

    <body> <div class="body"><img src="bopin/images/bigImg1.jpg" widt ...

  10. JS Date

    JS获取当前日期时间 var myDate = new Date();myDate.getFullYear();    //获取完整的年份(4位,1970-????)myDate.getMonth() ...