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. python学习之数据类型与运算符号

    python版本:3.6 python编辑器:pycharm 最新版本 整理成代码如下: #!/usr/bin/env python #-*- coding: utf-8 -*- # 数学操作符 pr ...

  2. 猴子吃桃问题 python

    猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个,第二天早上又将剩下的桃子吃掉一半,又多吃了一个.以后每天早上都吃了前一天剩下的一半零一个.到第10天早上想再吃时,见只剩下一个桃子了.求第 ...

  3. 005--Django2.0的路由层

    URL配置就像Django所支撑的网站目录,它的本质是每条URL调用的视图函数的映射表,每一个请求执行对应的视图函数. 1.简单的路由配置  from django.contrib import ad ...

  4. Android面试收集录17 Android进程优先级

    在安卓系统中:当系统内存不足时,Android系统将根据进程的优先级选择杀死一些不太重要的进程,优先级低的先杀死.进程优先级从高到低如下. 前台进程 处于正在与用户交互的activity 与前台act ...

  5. luoguP1726 上白泽慧音

    P1726 上白泽慧音 题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村 ...

  6. notepad++ 换行技巧 log换行

    有时候,服务器收集上来的日志,格式很乱,看log很难,如下: java.lang.IllegalStateException: BEvent.init() must be call first\n\t ...

  7. HTML标准开头

    <!doctype html> <html>   <head> <meta charset="utf-8"> <title&g ...

  8. springmvc上传图片并显示--支持多图片上传

    实现上传图片功能在Springmvc中很好实现.现在我将会展现完整例子. 开始需要在pom.xml加入几个jar,分别是: <dependency> <groupId>comm ...

  9. 《Cracking the Coding Interview》——第18章:难题——题目6

    2014-04-29 02:27 题目:找出10亿个数中最小的100万个数,假设内存可以装得下. 解法1:内存可以装得下?可以用快速选择算法得到无序的结果.时间复杂度总体是O(n)级别,但是常系数不小 ...

  10. Java EE - JSP 小结

    Table of Contents 前言 JSP 与 Servlet JSP 初始化参数 脚本元素 page 指令 禁用脚本元素 EL 表达式 EL 函数 taglib 指令 标记 TLD 文件的位置 ...