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. MyFirstDay(附6篇python亲历面试题)

    一直以来都是在看别人写的内容,学习前辈们的经验,总感觉自己好像没有什么值得拿出来分享和交流的知识,最近在准备换工作(python后端开发),坐标上海,2019年3月,半个月面了6家(感觉效率是真不高. ...

  2. 数据结构学习-BST二叉查找树 : 插入、删除、中序遍历、前序遍历、后序遍历、广度遍历、绘图

    二叉查找树(Binary Search Tree) 是一种树形的存储数据的结构 如图所示,它具有的特点是: 1.具有一个根节点 2.每个节点可能有0.1.2个分支 3.对于某个节点,他的左分支小于自身 ...

  3. 3,MongoDB之数据类型

    一.MongoDB 之数据类型 首先我们要先了解一下MongoDB中有什么样的数据类型: Object  ID :Documents 自生成的 _id String: 字符串,必须是utf-8 Boo ...

  4. 01,jupyter环境安装

    jupyter notebook环境安装 一.什么是Jupyter Notebook? 1. 简介 Jupyter Notebook是基于网页的用于交互计算的应用程序.其可被应用于全过程计算:开发.文 ...

  5. 4 . GET方法实现文章分类

    复习:博客站点 <!DOCTYPE html> {% load staticfiles %} <html> <head> <meta charset=&quo ...

  6. error: unknown host service 的详细解决办法

    问题情况描述: 有时候,你在cmd 窗口 adb shell 的时候,出现error: unknown host service. 问题解决办法: 这就要怪可恶的360手机助手了,你在任务管理器里面把 ...

  7. long转int

    由int类型转换为long类型是向上转换,可以直接进行隐式转换,但由long类型转换为int类型是向下转换,可能会出现数据溢出情况: 主要以下几种转换方法,供参考: 一.强制类型转换 [java] l ...

  8. Django 2.0官方文档中文 总索引

    Django 2.0官方文档中文 渣翻 总索引 翻译 2017年12月08日 11:19:1 官方原文: https://docs.djangoproject.com/en/2.0/ 当前翻译版本:  ...

  9. 有关ViewPager的使用及解决Android下ViewPager和PagerAdapter中调用notifyDataSetChanged失效的问题

    ViewPager是android-support-v4.jar包中的一个系统控件,继承自ViewGroup,专门用以实现左右滑动切换View的效果,使用时需要首先在Project->prope ...

  10. 剑指Offer - 九度1370 - 数组中出现次数超过一半的数字

    剑指Offer - 九度1370 - 数组中出现次数超过一半的数字2013-11-23 03:55 题目描述: 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如输入一个长度为9的数组 ...