题目链接: 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. Android-修改TabWidget字体大小颜色及对齐

    在Android中,我们可以定义TabWidget来分页.在上一篇文章中有说到使用TabWidget定义Tab分页布局,但大部分用户可能会觉得默认的字体有点小,但Tab选项卡默认又不能设定字体大小,如 ...

  2. R语言-处理异常值或报错的三个示例

    博客总目录:http://www.cnblogs.com/weibaar/p/4507801.html Tuesday, March 31, 2015 之前用rvest帮人写了一个定期抓取amazon ...

  3. uboot学习第一天

    Windows操作系统BIOS(设置) Windows系统 文件系统 驱动程序 应用程序 linux操作系统bootloader(引导系统) kernel(内核) 文件系统 驱动程序 应用程序 交叉编 ...

  4. 微信 5.3 for iPhone已放出 微信iphone版更新下载

    就在几个小时前,微信发布了更新,本次只放出微信 5.3 for iPhone,距离发布微信5.3内测版也就几天时间.和往常一样微信iphone版先发布,微信android版延后发布,微信看重的是ios ...

  5. 【转】4G内存下MySQL修改配置文件以优化效率(来自discuz)

    摘要:公司网站访问量越来越大,MySQL自然成为瓶颈,因此最近我一直在研究 MySQL 的优化,第一步自然想到的是 MySQL 系统参数的优化,作为一个访问量很大的网站(日20万人次以上)的数据库. ...

  6. 搭建 Windows Server 2003 + IIS6.0 + FastCGI + PHP5.3.29 + MySQL5.5.38 + Memcached1.2.6

    一.下载相关软件: 1.VC9运行库 即VISUAL C++ 2008 自PHP5.3.0开始,PHP提供VC2008编译版,需要安装VC++ 2008的运行库. [微软官方下载] http://ww ...

  7. C和指针 第十二章 使用结构和指针

    链表是一种常用的数据结构,每个节点通过链或者指针链接在一起,程序通过间接指针访问链表中的节点. typedef struct Node { //指向下一个节点的指针 struct Node *next ...

  8. EasyUI创建异步树形菜单和动态添加标签页tab

    创建异步树形菜单 创建树形菜单的ul标签 <ul class="easyui-tree" id="treeMenu"> </ul> 写j ...

  9. ftp服务配置文件记录

    因为南京的客户死活要ftp服务而不是sftp,所以我作手用vsftp作为服务器,尝试在windows ftp软件登录进去,特记录vsftp的用法. 配置文件在/etc/vsftpd.conf 有如下代 ...

  10. espcms内容页上下篇按后台手动排序号

    模板文件: {%get name=plist class="did":$read.did,pid:$read.pid%} <li class="fl"&g ...