题目链接: 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. 安全测试及B/S C/S安全性比较

    一.用户认证安全的测试要考虑问题: 1.        明确区分系统中不同用户权限 2.        系统中会不会出现用户冲突 3.        系统会不会因用户的权限的改变造成混乱 4.     ...

  2. cf723b Text Document Analysis

    Modern text editors usually show some information regarding the document being edited. For example, ...

  3. 用类方法------>快速创建一个autorelease的对象,在封装的类方法内部

    在封装的类方法内部,也就是+ (id)personWithName:(NSString *)name andAge:(int)age内部: 创建了一个person对象,并且创建了一个person*类型 ...

  4. ZOJ 3699 Dakar Rally

    Dakar Rally Time Limit: 2 Seconds      Memory Limit: 65536 KB Description The Dakar Rally is an annu ...

  5. 苹果微信下载 iOS微信各版本列表

    微信在不断地更新迭代,ios微信下载点击这里立即开始(手机电脑都可以,电脑端要安装iTunes),每个版本都放出一些新的功能或修复相关错误,详情可以点击下面的版本链接进行查看.(这里有Android微 ...

  6. java 读文件路径问题

    文件路径:右键点击src新建Source Folder,创建结果与src目录同级. C:\Users\lenovo\workspace\timedTask\config\userinfo.proper ...

  7. connect 链接失败: 查找不到 signal

                提示错误是:   signal_index < 0 ;;     ----  故 connect返回false;              消除  connect  信号 ...

  8. day3

    程序1: 实现简单的shell sed替换功能 ]new = sys.argv[]file_name = sys.argv[]tmp_file ="tmpfile"open(tmp ...

  9. 基于Z-WAVE 协议的LED智能照明系统的研究笔记

    LED调光基础: ☆:LED照明调光控制信号的方式有两种: 1. 通过PWM信号控制LED灯具开关电源的占空比从而实现调光: 2. 通过调光控制信号和交流电源供电线合用的两线式或三线式(例如LED相控 ...

  10. JavaScript高级程序设计学习笔记--BOM

    window对象 BOM的核心对象是window,它表示浏览器的一个实例.在浏览器中,window对象有双重角色,它既是通过JavaScript访问浏览器窗口的一个接口,又是ECMScript规定的G ...