题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1892

See you~

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

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
题意:标准的二维梳妆数组
这个题,为了让输入和输出更快一点,因为要输入输出的数据量很大所以可以使用输入输出外挂 。开始赋值的时候因为每个格子都是1,而树状数组(x,y)表示的又是从(lowbit(x),lowbit(y))到(x,y)的面积内的书,所以可以用求面积的方法初始化树状数组
下面是代码:
 #include<cstdio>
#include <iostream>
#include<cstring>
#include<algorithm> using namespace std;
#define N 1010
inline int lowbit(int i)
{
return i&(-i);
} int mp[N][N];
inline int add(int x , int y , int a)
{
for(int i = x ; i < N ;i+=lowbit(i))
for(int j = y ; j < N ;j+=lowbit(j))
mp[i][j]+=a;
}
inline int sum (int x , int y)
{
int ans = ;
for(int i = x ; i> ; i-=lowbit(i))
for(int j = y ; j> ; j-=lowbit(j))
ans+=mp[i][j];
return ans;
}
inline int Sum(int x1,int y1,int x2,int y2)
{
int ans = sum(x2,y2)-sum(x1-,y2)-sum(x2,y1-)+sum(x1-,y1-);
return ans;
}//写成内敛函数会更快一点
inline int in_int()//输入外挂读入一个数字
{
char ch;
int res = ;
while(ch = getchar()) if(ch >= '' && ch <= '') break;
while(ch >= '' && ch <= '')
{
res = res*+ch-'';
ch = getchar();
}
return res;
} inline char in_ch()//输入外挂读入一个字符
{
char res = getchar();
while(res < 'A' || res > 'Z') res = getchar();
return res;
} void out(int x)//递归的输出外挂其实并不会快多少
{
if(x > ) out(x/);
putchar(x%+'');
}
int iniAry[N][N]; int main()
{
for(int i = ; i < N; i++)
for(int j = ; j < N; j++)
iniAry[i][j] = lowbit(i)*lowbit(j); //因为每次的初始化都是一样的,所以可以只算一次,然后memcpy()给mp;
int T;
T = in_int();
for(int cas = ; cas <= T; cas++)
{
printf("Case %d:\n", cas);
memcpy(mp, iniAry, sizeof(iniAry));
int n;
n = in_int();
char ml;
for(int i = ;i < n; i++)
{
ml = in_ch();
if(ml=='S')
{
int x1, x2,y1,y2;
x1 = in_int();
y1 = in_int();
x2 = in_int();
y2 = in_int();
x1++, y1++, x2++, y2++;
if(x1 > x2) swap(x1, x2);
if(y1 > y2) swap(y1, y2);
int sum = Sum(x1,y1,x2,y2);
out(sum);
puts("");
}
else if(ml == 'A')
{
int x , y, a;
x = in_int();
y = in_int();
x++, y++;
a = *in_int();
add(x,y,a);
}
else if(ml == 'D')
{
int x, y, m;
x = in_int();
y = in_int();
x++, y++;
m = in_int();
int tm = Sum(x, y, x, y);
if(tm < m) m = tm;
if(m > ) add(x, y, -m);
}
else if(ml =='M')
{
int x1 , x2, y1, y2, m;
x1 = in_int();
y1 = in_int();
x2 = in_int();
y2 = in_int();
x1++, y1++, x2++, y2++;
m = in_int();
int tm = Sum(x1, y1, x1, y1);
if(tm < m) m = tm;
if(m > )
{
add(x1,y1,-m);
add(x2,y2,m);
}
}
}
}
return ;
}

See you~(二维树状数组)的更多相关文章

  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)上的数全部 ...

  10. MooFest_二维树状数组

    Description Every year, Farmer John's N (1 <= N <= 20,000) cows attend "MooFest",a s ...

随机推荐

  1. Noip2016换教室(期望+DP)

    Description 题目链接:Luogu Solution 这题结合了DP和概率与期望,其实只要稍微知道什么是期望就可以了, 状态的构造很关键,\(F[i][j][0/1]\)表示已经到第\(i\ ...

  2. 【USACO】玉米实验(单调队列)

    Description 约翰决定培育新的玉米品种以提高奶牛的产奶效率.约翰所有的土地被分成 N ×N 块,其中第 r行第 c 列的玉米质量为 Ar,c.他打算找一块质量比较均匀的土地开始自己的实验.经 ...

  3. xamarin android viewpager的用法

    1.什么是ViewPager 通过手势滑动可以完成view的切换,一般是用来app的引导页或则实现图片轮播,类似网页上的banner轮播. Adnroid 3.0后引入的一个UI控件,在xamarin ...

  4. ArcGIS 网络分析[1.4] 制作点线要素时需要注意的地方

    有很多同学虽然成功做好了网络数据集,但是分析时会出现这样的问题: 这是为什么呢? 这有三个可能的原因: 1. 两个点之间所有的道路没有连通(问题出在点.线数据上). 2. 网络数据集出现了孤立的点位置 ...

  5. uniq 命令详解

    作用: 报告或忽略文件中的重复行,一般与sort 连用. 选项:-c count 在每列前显示该行重复出现的次数     -d repeated, 仅显示重复出现的行列     -f skip fie ...

  6. go generate 生成代码

    今后一段时间要研究下go generate,在官网博客上看了Rob Pike写的generating code,花了一些时间翻译了下.有几个句子翻译的是否正确有待考量,欢迎指正. 生成代码 通用计算的 ...

  7. Q:javax.comm 2.0 windows下Eclipse的配置

    @转自http://blog.csdn.net/zhuanghe_xing/article/details/7523744处 要在Windows下,对计算机的串口或并口等进行编程,可以选择使用Java ...

  8. Gradle、Gradle Wrapper与Android Plugin for Gradle

    欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...

  9. python导入不同目录下模块的方法

    下面将具体介绍几种常用情况:(1)主程序与模块程序在同一目录下:如下面程序结构:`-- src    |-- mod1.py    `-- test1.py    若在程序test1.py中导入模块m ...

  10. Mac Sublime text3 如何设置更加漂亮好用?

    说明:配置是根据自己的需求搜索了蛮多博客测试总结的. 显示效果 配置信息: command + , [逗号], 右侧配置信息 { "color_scheme": "Pac ...