HDU 1892-See you(二维BIT)
题意:
最多1000*1000的方格,各方格开始有一本书
有四种操作:对指定方格把书拿走或向里面放书,从一个方格那一定量的书放到另一个方格,查询给定对角线顶点的坐标的矩形范围内包含的书的总数
分析:
二维BIT,注意方格的书数小于拿书数量的情况
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define N 1010
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int sum[N][N],n,a[N][N];
int lowbit(int x){
return (x)&(-x);
}
void add(int x,int y,int v){
for(int i=x;i<N;i+=lowbit(i))
for(int j=y;j<N;j+=lowbit(j)){
sum[i][j]+=v;
}
}
int sum1(int x,int y){
int num=;
for(int i=x;i>;i-=lowbit(i))
for(int j=y;j>;j-=lowbit(j))
num+=sum[i][j];
return num;
}
int main()
{
int t,test=;
char op[];
int x1,x2,y1,y2,v,q;
scanf("%d",&t);
while(t--){
memset(sum,,sizeof(sum));
for(int i=;i<N;++i)
for(int j=;j<N;++j){
a[i][j]=;
add(i,j,);
}
printf("Case %d:\n",++test);
scanf("%d",&q);
while(q--){
scanf("%s",op);
if(op[]=='S'){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
int sx=min(x1,x2);
int ex=max(x1,x2);
int sy=min(y1,y2);
int ey=max(y1,y2);
sx++;ex++;
sy++;ey++;
int tmp=sum1(ex,ey)-sum1(sx-,ey)-sum1(ex,sy-)+sum1(sx-,sy-);
printf("%d\n",tmp);
}
else if(op[]=='A'){
scanf("%d%d%d",&x1,&y1,&v);
x1++;
y1++;
add(x1,y1,v);
a[x1][y1]+=v;
}
else if(op[]=='D'){
scanf("%d%d%d",&x1,&y1,&v);
x1++;
y1++;
if(v>a[x1][y1])v=a[x1][y1];
add(x1,y1,-v);
a[x1][y1]-=v;
}
else if(op[]=='M'){
scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&v);
x1++;y1++;
x2++;y2++;
if(a[x1][y1]<v)
v=a[x1][y1];
add(x1,y1,-v);
add(x2,y2,v);
a[x1][y1]-=v;
a[x2][y2]+=v;
}
}
}
return ;
}
HDU 1892-See you(二维BIT)的更多相关文章
- HDU 1892 See you~ (二维树状数组)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1892 See you~ Problem Description Now I am leaving h ...
- HDU 1892(书架统计 二维树状数组)
题意是在二维平面上在一些位置上进行数据的增删改查操作,使用树状数组(了解树状数组点这里) 原来的树状数组在求区间和时是 sum( x, y ) = getsum( y ) - getsum( x - ...
- HDU 2159 FATE(二维费用背包)
FATE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- HDU 2159 FATE (二维完全背包
FATE http://acm.hdu.edu.cn/showproblem.php?pid=2159 Problem Description 最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备 ...
- 【 HDU - 4456 】Crowd (二维树状数组、cdq分治)
BUPT2017 wintertraining(15) #5A HDU 4456 题意 给你一个n行n列的格子,一开始每个格子值都是0.有M个操作,p=1为第一种操作,给格子(x,y)增加z.p=2为 ...
- Hdu 2888 Check Corners (二维RMQ (ST))
题目链接: Hdu 2888 Check Corners 题目描述: 给出一个n*m的矩阵,问以(r1,c1)为左上角,(r2,c2)为右下角的子矩阵中最大的元素值是否为子矩阵的顶点? 解题思路: 二 ...
- HDU 4819 Mosaic (二维线段树)
Mosaic Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total S ...
- HDU 2159 FATE【二维完全背包】
题意:xhd玩游戏,还需要n个经验值升级,还留有m的忍耐度,但是他最多打s只怪,给出k个怪的经验值a[i],以及消耗的忍耐度b[i],问xhd能不能升级-- 因为有两个限定,忍耐度,和最多打s只怪(即 ...
- HDU 3127 WHUgirls【二维完全背包】
题意:给出一个长为a,宽为b的布,再给出n个围巾的规格(长x,宽y,价值c),问怎样裁剪能够得到最大的价值. ----第一次做的时候不会---然后放到今天做--发现还是不会---于是又--看题解了-- ...
随机推荐
- 李洪强iOS开发支付集成之微信支付
iOS开发支付集成之微信支付 微信支付也是需要签名的,也跟支付宝一样,可以在客户端签名,也可以在后台签名(当然,为了安全还是推荐在服务器上做签名,逻辑也比较好理解). 1 - 集成前首先要看看文档 开 ...
- HTML5入门4---HTML5 与 HTML4 同一网页的不同写法
HTML4写法 css: body { font-family: "Lucida Sans Unicode", "Lucida Grande", Verdana ...
- Google不做坏事吗?
说中国足球为什么冲不出亚洲,那是因为咱中国人太文气,足球是种“斗牛士”式的游戏,得玩的有点儿“野蛮”色彩.记得以前在英国的时候,遇上联赛,晚上大街小巷全民皆兵,曼切斯特队的粉丝在街道一边酒吧里,利物浦 ...
- Delphi语言获得生命的原因和过程
都说Anders Hejlsberg是Delphi语言的作者,前一阵仔细读了VCL源码,惊叹于它的巧夺天工,未免对编译器的作者有些不服气,觉得首功不是他.今天仔细想了想,还是觉得不服不行.以下是我的理 ...
- servlet会话技术:Session
问题的引出 1.在网上购物时,张三和李四购买的商品不一样,他们的购物车中显示的商品也不一样,这是怎么实现的呢? 2.不同的用户登录网站后,不管该用户浏览该网站的那个页面,都可以显示登录人的名字,同时可 ...
- 259. 3Sum Smaller
题目: Given an array of n integers nums and a target, find the number of index triplets i, j, k with 0 ...
- HDU5093——Battle ships(最大二分匹配)(2014上海邀请赛重现)
Battle ships Problem DescriptionDear contestant, now you are an excellent navy commander, who is res ...
- c 语言练习__求到N的阶乘的和。
#include <stdio.h> /* 题目如下 * S = 1 + 2! + 3! + ... + N! */ int main(int argc, char *argv[]) { ...
- WIN7 64位系统搭建WINCE6.0系统遇到的问题
WIN7 64位系统搭建WINCE6.0系统遇到的问题 安装顺序如下: .先装Visual Studio2005: .安装Visual Studio2005 Service Pack 1: .安装Vi ...
- BZOJ 1297 迷路(矩阵)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1297 题意:给出一个带权有向图,权值为1-9,顶点个数最多为10.从1出发恰好在T时刻到 ...