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. jquery 配合 ajax 完成 在线编辑 你值得拥有

    思路分析: 将 table中的表格 改变成为 input表格框获得值 ajax配合修改 删除 <?php use yii\helpers\Url; $web = Url::base(); ?&g ...

  2. python-4函数式编程

    1-高阶函数 变量可以指向函数.   def add(x, y, f): 例如f参数为函数 编写高阶函数,就是让函数的参数能够接收别的函数. Python内建了map()和reduce()高阶函数. ...

  3. 笔记-git-git服务器安装及配置

    笔记-git-git服务器安装及配置 1.      GIT服务器简介 Git 可以使用四种主要的协议来传输数据:本地传输,SSH 协议,Git 协议和 HTTP 协议.下面分别介绍一下哪些情形应该使 ...

  4. Python文章推荐1

    Table of Contents 1. 分享最近看到的python相关的几篇好文(我只是想偷懒) 1.1. 形象解释了什么是GIL 1.2. 知乎上 Pythonic 相关 1.3. evil &q ...

  5. JS是如何计算 1+1=2 的?

    身为程序员多年,作者今天突然对这件事感到十分好奇了.我问计算机芸芸部件,1+1究竟是如何计算的,他们都茫然的看着我. 打开谷歌浏览器->Console面板,大脑向双手不停发送生物电信号,肌肉细胞 ...

  6. 3226: [Sdoi2008]校门外的区间

    链接 思路 bug漫天飞... 维护一颗线段树,支持区间赋值,和区间异或.因为会处理到一些方括号还是圆括号的问题,所以对于每一个下标都乘2,假设中间有一个.5即可,都变成了方括号,输出在处理一下. U ...

  7. android的dmtracedump工具生成trace文件图片 'dot' 不是内部或外部命令,也不是可运行的程序 或批处理文件。

    http://jingyan.baidu.com/article/c910274bfa6c1fcd361d2df7.html http://www.cnblogs.com/albert1017/p/3 ...

  8. Retrofit get post query filed FiledMap

    直接请求型 1.如果是直接请求某一地址,写法如下: @GET("/record") Call getResult(); 2.如果是组合后直接请求,如/result/{id}写法如下 ...

  9. MyEclipse - 问题集 - build properties does not exist

    方案1 受MyEclipse生成的项目文件.project影响,检查其中是否含有“<nature>org.eclipse.pde.PluginNature</nature>”, ...

  10. Github前端项目排名

      Github前端项目排名(2016-04-04) 一.前言 近几年前端技术日新月异,从 RequireJS 到 AngularJS 再到 React,似乎每天都有新的技术诞生.而大神们总能第一时间 ...