HDU1892 See you~
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 4660 Accepted Submission(s): 1479
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.
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.
For each "S" query, just print out the total number of books in that area.
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
1
3
Case 2:
1
4
用二位树状数组模拟单点修改和区间查询。
/**/
#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~的更多相关文章
- HDU1892二维树状数组
See you~ Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Su ...
- See you~ HDU1892
一开始还离散化弄了好久 离散化细节弄得好差 这题用二维树状数组做很快 因为树状数组下标不为0 所以所有下标要加一处理 还有就是算矩阵的时候要处理两个坐标的大小关系 个人感觉树状数组用for语句写 ...
- hdu-1892 See you~---二维树状数组运用
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1892 题目大意: 题目大意:有很多方格,每个方格对应的坐标为(I,J),刚开始时每个格子里有1本书, ...
- See you~(hdu1892)
See you~ Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Su ...
- BZOJ1173 CDQ分治 笔记
目录 二维数据结构->cdq 预备知识 T1: 二维树状数组 T2:cdq分治 bzoj1176 mokia:Debug心得 一类特殊的CDQ分治 附: bzoj mokia AC代码 二维数据 ...
随机推荐
- php扩展开发-全局变量
//php_myext.hZEND_BEGIN_MODULE_GLOBALS(myext) unsigned long counter;//在这里定义需要的全局变量,可以多个,每个变量一行, ZEND ...
- Java面试宝典2017版
1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语法,集合的语法,io 的语法,虚拟机方面的语法. 1.一个".java&qu ...
- Python中的not, and, or
logical_operator_lst = [ ('and 与运算',), ('or 或运算',), ('not 非运算',), ('逻辑运算符的优先级',), ('实例',), ('练习',), ...
- 部分和问题 南阳acm1058(递归+dfs)
部分和问题 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 给定整数a1.a2........an,判断是否可以从中选出若干数,使它们的和恰好为K. 输入 首先, ...
- PHP.17-文本式留言板
文本式留言板 思路: 1.首页:index.php 添加/查看信息界面 单纯的表单页面,注意留言内容为文本域<textarea> 2.添加信息页面:doAdd.php 1.获取要添加的留 ...
- CSS计数器(自定义列表)
概念 CSS3计数器(CSS Counters)可以允许我们使用css对页面中的任意元素进行计数,实现类似于有序列表的功能(自定义有序列表) 与有序列表相比,它的突出特性在于可以对任意元素计数,同时实 ...
- 使用Eclipse把java文件打包成jar
本例仅限于要打包的文件没有使用第三方的jar包 在要打包的包或者文件上右键-Export 这里有一些选项: Export generated class files and resources 表示只 ...
- linux 多播
1.概念 单播是用于两个主机之间传送数据,广播是一个主机对局域网内的所有主机发送数据.而多播,又称为组播,它是对一组特定的主机通信.将网络上同一类型 业务逻辑上分组,只和组内的成员通信,其它主机没有加 ...
- 【HTML&CSS】 第一章:DTD文档声明
<!DOCTYPE> 声明必须是 HTML 文档的第一行,位于 <html> 标签之前. <!DOCTYPE> 声明不是 HTML 标签:它是指示 web 浏览器关 ...
- 使用系统的某些block api(如UIView的block版本写动画时),是否也考虑循环引用问题?
系统的某些block api中,UIView的block版本写动画时不需要考虑,但也有一些api 需要考虑 以下这些使用方式不会引起循环引用的问题 [UIView animateWithDuratio ...