See you~

Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 4729    Accepted Submission(s): 1515

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
 题意:
二维坐标平面内,在x,y>=0的点中,每一个点刚开始都有一本书,有4种操作,S求x1,y1,x2,y2,两个点的横纵坐标围成的矩形内有多少书。
代码:
 /*由于x,y从0开始,所以把每一个x,y加一,否则会陷入死循环*/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int t,q;
int A[][];
int lowbit(int x)
{
return x&(-x);
}
void add(int x,int y,int c)
{
for(int i=x;i<=;i+=lowbit(i))
{
for(int j=y;j<=;j+=lowbit(j))
A[i][j]+=c;
}
}
int sum(int x,int y)
{
int s=;
for(int i=x;i>;i-=lowbit(i))
{
for(int j=y;j>;j-=lowbit(j))
s+=A[i][j];
}
return s;
}
int ans(int x1,int y1,int x2,int y2)
{
return (sum(x2,y2)-sum(x1-,y2)-sum(x2,y1-)+sum(x1-,y1-));
}
int main()
{
int x1,y1,x2,y2,n1;
char ch;
scanf("%d",&t);
for(int k=;k<=t;k++)
{
printf("Case %d:\n",k);
memset(A,,sizeof(A));
scanf("%d",&q);
for(int i=;i<;i++)
for(int j=;j<;j++)
add(i,j,);
while(q--)
{
cin>>ch;
if(ch=='S')
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1>x2) //交换,求的是一个矩形区域所以交换后结果不会变
{
x1=x1^x2;
x2=x1^x2;
x1=x1^x2;
}
if(y1>y2)
{
y1=y1^y2;
y2=y1^y2;
y1=y1^y2;
}
printf("%d\n",ans(x1+,y1+,x2+,y2+));
}
else if(ch=='A')
{
scanf("%d%d%d",&x1,&y1,&n1);
add(x1+,y1+,n1);
}
else if(ch=='D')
{
scanf("%d%d%d",&x1,&y1,&n1);
int num=ans(x1+,y1+,x1+,y1+);
add(x1+,y1+,-(num>n1?n1:num));
}
else
{
scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&n1);
int num=ans(x1+,y1+,x1+,y1+);
add(x1+,y1+,-(num>n1?n1:num));
add(x2+,y2+,num>n1?n1:num);
}
}
}
return ;
}

HDU1892二维树状数组的更多相关文章

  1. 二维树状数组 BZOJ 1452 [JSOI2009]Count

    题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...

  2. HDU1559 最大子矩阵 (二维树状数组)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1559 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others)  ...

  3. POJMatrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 22058   Accepted: 8219 Descripti ...

  4. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  5. Codeforces Round #198 (Div. 1) D. Iahub and Xors 二维树状数组*

    D. Iahub and Xors   Iahub does not like background stories, so he'll tell you exactly what this prob ...

  6. POJ 2155 Matrix(二维树状数组+区间更新单点求和)

    题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...

  7. [poj2155]Matrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25004   Accepted: 9261 Descripti ...

  8. POJ 2155 Matrix (二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17224   Accepted: 6460 Descripti ...

  9. [POJ2155]Matrix(二维树状数组)

    题目:http://poj.org/problem?id=2155 中文题意: 给你一个初始全部为0的n*n矩阵,有如下操作 1.C x1 y1 x2 y2 把矩形(x1,y1,x2,y2)上的数全部 ...

随机推荐

  1. Hibernate的核心API

    Configuration:负责管理Hibernate的配置信息 1.加载核心配置文件 核心配置有两种: hibernate.properties 加载:Configuration configura ...

  2. 常用chrome插件推荐

    下面打红色的2个强烈推荐使用: FQ的: https://chrome.google.com/webstore/detail/ecross-free/njdjpgffklilbojbobbfecfcg ...

  3. Swift3.0语言教程查找字符集和子字符串

    Swift3.0语言教程查找字符集和子字符串 Swift3.0语言教程查找字符集和子字符串,在字符串中当字符内容很多时,我们就需要使用到查找字符集或者子字符串的方法.以下我们将讲解3种查找字符集和子字 ...

  4. 移动网站中,用canvas,svg比用图片好?

    1.Svg可以单独作为文件打开,在AI里做矢量图形,保存图层路径,即可另存为Svg文件. (1) Path语法:命令+参数.大写字母表示坐标参数为绝对位置,小写字母表示坐标参数为相对位置(即上次画笔结 ...

  5. PHP学习笔记(一)

    by Alina.Xia, dated on 2016.11.27 一.MyAql数据库PHP在开发web站点或管理一些系统时,需要对大量的数据进行保存.XML文件和文本文件虽然可以作为数据的整体,但 ...

  6. hdu 1059 Dividing

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  7. Sharepoint超期触发列表工作流提醒

    项目背景 Sharepoint 2010 ,Infopath 2010环境,用Infopath设置好表单把数据提交到Sharepoint的Library库.很常见的需求,其中有一个[状态]字段,[申请 ...

  8. Codeforces Round #343 (Div. 2)

    居然补完了 组合 A - Far Relative’s Birthday Cake import java.util.*; import java.io.*; public class Main { ...

  9. BIT LA 4329 Ping pong

    题目传送门 题意:训练指南P197 分析:枚举裁判的位置,用树状数组来得知前面比它小的和大的以及后面比它小的和大的,然后O (n)累加小 * 大 + 大 * 小 就可以了 #include <b ...

  10. Codeforces 677E Vanya and Balloons(DP + 一些技巧)

    题目大概说给一张地图,地图每个格子都有0到9中的某一个数字.现在要在一个格子放炸弹,炸弹爆炸后水柱有两种扩展方式,一种是上.下.左.右,另一种是左上.右下.右上.左下,且四个方向的长度都一样.问放哪个 ...