Codeforces Round #296 (Div. 1) A. Glass Carving Set的妙用
2 seconds
256 megabytes
standard input
standard output
Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm × h mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of what to carve and how.
In order not to waste time, he decided to practice the technique of carving. To do this, he makes vertical and horizontal cuts through the entire sheet. This process results in making smaller rectangular fragments of glass. Leonid does not move the newly made glass fragments. In particular, a cut divides each fragment of glass that it goes through into smaller fragments.
After each cut Leonid tries to determine what area the largest of the currently available glass fragments has. Since there appear more and more fragments, this question takes him more and more time and distracts him from the fascinating process.
Leonid offers to divide the labor — he will cut glass, and you will calculate the area of the maximum fragment after each cut. Do you agree?
The first line contains three integers w, h, n (2 ≤ w, h ≤ 200 000, 1 ≤ n ≤ 200 000).
Next n lines contain the descriptions of the cuts. Each description has the form H y or V x. In the first case Leonid makes the horizontal cut at the distance y millimeters (1 ≤ y ≤ h - 1) from the lower edge of the original sheet of glass. In the second case Leonid makes a vertical cut at distance x (1 ≤ x ≤ w - 1) millimeters from the left edge of the original sheet of glass. It is guaranteed that Leonid won't make two identical cuts.
After each cut print on a single line the area of the maximum available glass fragment in mm2.
4 3 4
H 2
V 2
V 3
V 1
8
4
4
2
7 6 5
H 4
V 3
V 5
H 2
V 1
28
16
12
6
4
Picture for the first sample test:
Picture for the second sample test:
题意:
给你n*m大的矩形,然后会切k刀,让你输出每切一刀后所分割的小矩形的最大面积是多少
题解
最大的小矩形,那么就应该是最大的长乘以最大的宽,我们用一个set存储所有切的位置,用一个数列来存储切之后每一段的长度是多少
然后我们一次递减查询就好,具体看代码吧~
代码:
int lenx[],leny[];
set<int> hor,ver;
int main()
{
int w,h,n,dis;
scanf("%d%d%d",&w,&h,&n);
hor.insert();
hor.insert(h);
leny[]++;
leny[h]++;
ver.insert();
ver.insert(w);
lenx[]++;
lenx[w]++;
set<int>::iterator itr,itr1,itr2;
char op[];
int maxy=h,maxx=w;
REP(i,n)
{
scanf("%s %d",op,&dis);
if(op[]=='H')
{
hor.insert(dis);
itr=hor.find(dis);
itr1=itr;
itr2=itr;
itr1--;
itr2++;
leny[*itr2-*itr1]--;
leny[*itr2-*itr]++;
leny[*itr-*itr1]++;
}
else
{
ver.insert(dis);
itr=ver.find(dis);
itr1=itr;
itr2=itr;
itr1--;
itr2++;
lenx[*itr2-*itr1]--;
lenx[*itr2-*itr]++;
lenx[*itr-*itr1]++;
}
while(!leny[maxy])maxy--;
while(!lenx[maxx])maxx--;
//cout<<maxy<<" "<<maxx<<endl;
printf("%I64d\n",1LL*maxx*maxy);
}
}
Codeforces Round #296 (Div. 1) A. Glass Carving Set的妙用的更多相关文章
- Codeforces Round #296 (Div. 2) C. Glass Carving [ set+multiset ]
传送门 C. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #296 (Div. 1) C. Data Center Drama 欧拉回路
Codeforces Round #296 (Div. 1)C. Data Center Drama Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xx ...
- CF #296 (Div. 1) A. Glass Carving 线段树
A. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- CodeForces Round #296 Div.2
A. Playing with Paper 如果a是b的整数倍,那么将得到a/b个正方形,否则的话还会另外得到一个(b, a%b)的长方形. 时间复杂度和欧几里得算法一样. #include < ...
- Codeforces Round #296 (Div. 1) E. Triangles 3000
http://codeforces.com/contest/528/problem/E 先来吐槽一下,一直没机会进div 1, 马力不如当年, 这场题目都不是非常难,div 2 四道题都是水题! 题目 ...
- 字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System
题目传送门 /* 无算法 三种可能:1.交换一对后正好都相同,此时-2 2.上面的情况不可能,交换一对后只有一个相同,此时-1 3.以上都不符合,则不交换,-1 -1 */ #include < ...
- 水题 Codeforces Round #296 (Div. 2) A. Playing with Paper
题目传送门 /* 水题 a或b成倍的减 */ #include <cstdio> #include <iostream> #include <algorithm> ...
- Codeforces Round #296 (Div. 2) A. Playing with Paper
A. Playing with Paper One day Vasya was sitting on a not so interesting Maths lesson and making an o ...
- Codeforces Round #296 (Div. 2) A B C D
A:模拟辗转相除法时记录答案 B:3种情况:能降低2,能降低1.不能降低分别考虑清楚 C:利用一个set和一个multiset,把行列分开考虑.利用set自带的排序和查询.每次把对应的块拿出来分成两块 ...
随机推荐
- 内核定时器的使用(好几个例子add_timer)【转】
转自:http://blog.csdn.net/jidonghui/article/details/7449546 LINUX内核定时器是内核用来控制在未来某个时间点(基于jiffies)调度执行某个 ...
- weblogic更改端口
两种方式: 1.访问console控制台页面,进入“环境\服务器\需要修改端口的服务器如AdminServer”,修改监听端口,保存并激活更改即可: 2.修改配置文件,进入weblogic的域目录,如 ...
- poj1056
简单题 #include <iostream> #include <string> using namespace std; struct cnode { cnode *pze ...
- node项目中用到的一些模块
1.http模块,用来搭建服务器 代码,简单服务器实现 var http = require('http'); http.createServer(function (request, respons ...
- 移动端默认meta标签
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><met ...
- No.11 selenium学习之路之浏览器大小
通过set_window_size()方法可以设置打开的浏览器大小 maximize_window()方法可以把当前浏览器最大化 例子:
- Linux基础 - tmux
安装 yum install tmux 类似vim当中存在命令行模式以及编辑模式,从编辑模式进入命令行模式需要先按ESC键,在tmux当中进行操作也要先准备好"姿势"再操作,默认情 ...
- Linux学习笔记:touch新建文件、修改访问、改动时间
touch用于创建新的空文件或者修改已有文件的时间戳. 语法:touch file.txt 如果file存在,使用touch指令可更改这个文件或目录的日期时间,包括存取时间和更改时间. 如果file不 ...
- Effective STL 学习笔记 31:排序算法
Effective STL 学习笔记 31:排序算法 */--> div.org-src-container { font-size: 85%; font-family: monospace; ...
- 企业级Docker Registry —— Harbor搭建和使用
本节内容: Harbor介绍 安装部署Harbor 环境要求 环境信息 安装部署harbor 配置harbor 配置存储 完成安装和启动harbor 访问Harbor 修改管理员密码 启动后相关容器 ...