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

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
 
Recommend
lcy
 

用二位树状数组模拟单点修改和区间查询。

 /**/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int mxn=;
int n;
int t[mxn][mxn];
inline int lowbit(int x){return x&-x;}
void add(int x,int y,int w){
while(x<mxn){
int tmp=y;
while(tmp<mxn){
t[x][tmp]+=w;
tmp+=lowbit(tmp);
}
x+=lowbit(x);
}
}
int query(int x,int y){
int res=;
while(x){
int tmp=y;
while(tmp){
res+=t[x][tmp];
tmp-=lowbit(tmp);
}
x-=lowbit(x);
}
return res;
}
int ask(int x,int y){
return query(x,y)-query(x-,y)-query(x,y-)+query(x-,y-);
}
int main(){
int T;
scanf("%d",&T);
int i,j;
for(int ro=;ro<=T;ro++){
//init
memset(t,,sizeof t);
for(i=;i<mxn;i++)
for(j=;j<mxn;j++)
add(i,j,);
//finish
printf("Case %d:\n",ro);
scanf("%d",&n);
char ch[];
int x1,y1,x2,y2;
int val;
while(n--){
scanf("%s",ch);
if(ch[]=='A'||ch[]=='D'){
scanf("%d%d%d",&x1,&y1,&val);
if(ch[]=='D')val=-(min(val,ask(x1+,y1+)));
add(x1+,y1+,val);
continue;
}
if(ch[]=='M'){
scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&val);
val=min(val,ask(x1+,y1+));
add(x1+,y1+,-val);
add(x2+,y2+,val);
continue;
}
else{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1<x2)swap(x1,x2);
if(y1<y2)swap(y1,y2);
int ans=query(x1+,y1+)-query(x2,y1+)-query(x1+,y2)+query(x2,y2);
printf("%d\n",ans);
}
}
}
return ;
}

HDU1892 See you~的更多相关文章

  1. HDU1892二维树状数组

    See you~ Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Su ...

  2. See you~ HDU1892

    一开始还离散化弄了好久  离散化细节弄得好差 这题用二维树状数组做很快  因为树状数组下标不为0  所以所有下标要加一处理 还有就是算矩阵的时候要处理两个坐标的大小关系 个人感觉树状数组用for语句写 ...

  3. hdu-1892 See you~---二维树状数组运用

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1892 题目大意: 题目大意:有很多方格,每个方格对应的坐标为(I,J),刚开始时每个格子里有1本书, ...

  4. See you~(hdu1892)

    See you~ Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Su ...

  5. BZOJ1173 CDQ分治 笔记

    目录 二维数据结构->cdq 预备知识 T1: 二维树状数组 T2:cdq分治 bzoj1176 mokia:Debug心得 一类特殊的CDQ分治 附: bzoj mokia AC代码 二维数据 ...

随机推荐

  1. TCP/IP协议之http和https协议

    一.TCP/IP协议 TCP/IP 是不同的通信协议的大集合. 1.TCP - 传输控制协议 TCP 用于从应用程序到网络的数据传输控制. TCP 负责在数据传送之前将它们分割为 IP 包,然后在它们 ...

  2. Linux相关常用命令

    1.XShell中上传文件命令 首先需要安装rz文件上传工具: yum -y install lrzsz 然后执行以下命令,可打开本地系统的选择文件窗口:(或者直接把本地的文件拖动到SSH Shell ...

  3. 1014-31-首页12-显示weibo未读数--后台运行---定时器

    /** *  当app进入后台时调用 */- (void)applicationDidEnterBackground:(UIApplication *)application{    /**     ...

  4. Android 热点相关操作

    Android未提供对该API的直接访问, 需要使用反射, 代码较简单, 如下 GetHotspotState.java package club.seliote.hotspotscanner.uti ...

  5. Fragment Touch事件泄露

    当Fragment的栈里面有几个fragment的时候,这个时候如果是几个fragment状态是hide,当你触摸当前fragment的时候,下层的fragment的事件被触发,这是由于Touch事件 ...

  6. python字典的整理信息

    字典的增删改查大纲 增: dic={'age':18,'name':'liu','sex':'male'} dic['high'] = 185 #没有键值对,添加 dic['age'] = 16 #有 ...

  7. Dapper.Extension的基本使用

    前言    上一篇随笔写了Dapper的简单的使用,这次写一下Dapper.Extension的使用,它是Dapper的简单的封装扩展,可以通过实例化的对象赋值后进行增删改的操作以及分页,但是却不能进 ...

  8. 110Balanced Binary Tree

    问题:判断二叉树是否为平衡二叉树分析:树上的任意结点的左右子树高度差不超过1,则为平衡二叉树.         搜索递归,记录i结点的左子树高度h1和右子树高度h2,则i结点的高度为max(h1,h2 ...

  9. 关于 package.json 和 package-lock.json 文件说明

    package.json 在 Node.js 中,模块是一个库或框架,也是一个 Node.js 项目.Node.js 项目遵循模块化的架构,当我们创建了一个 Node.js 项目,意味着创建了一个模块 ...

  10. erlang节点局域网通信

    节点1: F:\WorkSpace\Server\src>erl -name hw@192.168.10.142 -setcookie 4213 consulting .erlang in &q ...