hdu-1892-二维BIT
See you~
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 6520 Accepted Submission(s): 2040
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.
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<bits/stdc++.h>
using namespace std;
#define ULL unsigned long long
#define LL long long
LL C[][];
int A[][];
inline int lowbit(int x){return x&-x;}
void add(int x,int y,int d){
for(int i=x;i<=;i+=lowbit(i))
for(int j=y;j<=;j+=lowbit(j))
C[i][j]+=d;
}
LL sum(int x,int y){
LL r=;
for(int i=x;i>;i-=lowbit(i))
for(int j=y;j>;j-=lowbit(j))
r+=C[i][j];
return r;
}
int main(){
int t,x1,x2,y1,y2,n,q,cas=;
char ch[];
scanf("%d",&t);
while(t--){
memset(C,,sizeof(C));
for(int i=;i<=;++i)
for(int j=;j<=;++j) add(i,j,),A[i][j]=;
scanf("%d",&q);
printf("Case %d:\n",++cas);
while(q--){
scanf("%s",ch);
if(ch[]=='S'){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
x1++,y1++,x2++,y2++;
if(x1>x2) swap(x1,x2);
if(y1>y2) swap(y1,y2);
printf("%lld\n",sum(x2,y2)-sum(x1-,y2)-sum(x2,y1-)+sum(x1-,y1-));
}
else if(ch[]=='A'){
scanf("%d%d%d",&x1,&y1,&n);
x1++,y1++;
add(x1,y1,n);
A[x1][y1]+=n;
}
else if(ch[]=='D'){
scanf("%d%d%d",&x1,&y1,&n);
x1++,y1++;
n=min(n,A[x1][y1]);
add(x1,y1,-n);
A[x1][y1]-=n;
}
else if(ch[]=='M'){
scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&n);
x1++,y1++,x2++,y2++;
n=min(n,A[x1][y1]);
add(x1,y1,-n),A[x1][y1]-=n;
add(x2,y2,n),A[x2][y2]+=n;
}
}
}
return ;
}
hdu-1892-二维BIT的更多相关文章
- HDU 2159 二维费用背包问题
一个关于打怪升级的算法问题.. 题意:一个人在玩游戏老是要打怪升级,他愤怒了,现在,还差n经验升级,还有m的耐心度(为零就删游戏不玩了..),有m种怪,有一个最大的杀怪数s(杀超过m只也会删游戏的.. ...
- hdu 4819 二维线段树模板
/* HDU 4819 Mosaic 题意:查询某个矩形内的最大最小值, 修改矩形内某点的值为该矩形(Mi+MA)/2; 二维线段树模板: 区间最值,单点更新. */ #include<bits ...
- F - F HDU - 1173(二维化一维-思维)
F - F HDU - 1173 一个邮递员每次只能从邮局拿走一封信送信.在一个二维的直角坐标系中,邮递员只能朝四个方向移动,正北.正东.正南.正西. 有n个需要收信的地址,现在需要你帮助找到一个地方 ...
- HDU 3496 (二维费用的01背包) Watch The Movie
多多想看N个动画片,她对这些动画片有不同喜欢程度,而且播放时长也不同 她的舅舅只能给她买其中M个(不多不少恰好M个),问在限定时间内观看动画片,她能得到的最大价值是多少 如果她不能在限定时间内看完买回 ...
- hdu 2642 二维树状数组 单点更新区间查询 模板水题
Stars Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Subm ...
- hdu 2888 二维RMQ模板题
Check Corners Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- Coconuts HDU - 5925 二维离散化 自闭了
TanBig, a friend of Mr. Frog, likes eating very much, so he always has dreams about eating. One day, ...
- HDU 1263 二维map
题意:给出一份水果的交易表,根据地区统计出水果的交易情况. 思路:二维map使用. #include<cstdio> #include<string> #include ...
- hdu 2888 二维RMQ
Check Corners Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 2642二维树状数组 单点更新区间查询 模板题
二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html #include<stdio.h> #include& ...
随机推荐
- C/C++之学习笔记
[C语言的Static inline 函数的作用] [printf打印格式] %x 打印十六进制 %d 打印十进制 %b 打印二进制 %c 打印字符 %s 打印字符串 %f 打印单精度flo ...
- C++:struct和union 内存字节对齐问题
转自:http://blog.csdn.net/wangyanguiyiyang/article/details/53312049 struct内存对齐问题 1:数据成员对齐规则:结构(struct) ...
- pythoy的configparser模块
生成配置文件的模块 DEFAULT块,在以块为单位取块的值时,都会出现 import configparser config = configparser.ConfigParser() #相当于生成了 ...
- 20145127《java程序设计》第三次实验
实验三 敏捷开发与XP实践 一.实验内容及其步骤 1.配置开源中国公钥 2.找到ssh公钥 3.在开源中国添加公钥 4.下载同组同学项目 5.推送代码到开源中国 6.推送代码成功 二.实验感想总结: ...
- scp命令在linux间传送文件的方法
当两台LINUX主机之间要互传文件时可使用SCP命令来实现,建立信任关系之后可不输入密码. 把你的本地主机用户的ssh公匙文件复制到远程主机用户的~/.ssh/authorized_keys文件中 ...
- windows下如何解决chrome浏览器左下角总提示'Downloading proxy script'的问题
答:关掉LAN settings中的Automatically detect settings选项和Use automatic configuration script选项,如下图
- Linq in GroupBy GroupJoin
还是上一份的代码例子: public class Person { public int ID { get; set; } public string Name { get; set; } publi ...
- 第十一章 非对称加密算法--DH
注意:本节内容主要参考自<Java加密与解密的艺术(第2版)>第8章“高等加密算法--非对称加密算法” 11.1.非对称加密算法 特点: 发送方和接收方均有一个密钥对(公钥+私钥),其中公 ...
- Educational Codeforces Round 56 (Rated for Div. 2)
涨rating啦.. 不过话说为什么有这么多数据结构题啊,难道是中国人出的? A - Dice Rolling 傻逼题,可以用一个三加一堆二或者用一堆二,那就直接.. #include<cstd ...
- Ubuntu 14.04 更新gcc版本至4.9.2
参考: ubuntu 14.04 更新 gcc/g++ 4.9.2 Ubuntu 14.04 更新gcc版本至4.9.2 1.更新源,安装gcc v4.9.2 $ sudo add-apt-repos ...