Codeforces Round #296 (Div. 2) C. Glass Carving [ set+multiset ]
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:
10344839 | 2015-03-19 07:09:30 | njczy2010 | C - Glass Carving | GNU C++ | Accepted | 389 ms | 12556 KB |
题解:用两个set记录割点位置,用两个multiset记录割出来的块的大小
#include <cstdio>
#include <cstring>
#include <stack>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <set> #define ll long long
int const N = ;
int const M = ;
int const inf = ;
ll const mod = ; using namespace std; ll w,h,n;
set<ll> x;
set<ll> y;
multiset<ll> xp;
multiset<ll> yp;
ll xmax,ymax; void out(); void ini()
{
x.clear();y.clear();xp.clear();yp.clear();
x.insert();x.insert(w);
y.insert();y.insert(h);
xp.insert(w);yp.insert(h);
xmax=w;ymax=h;
// out();
} void solve()
{
ll i;
char s[];
ll v;
ll r,l;
ll le;
set<ll>::iterator it;
set<ll>::iterator it1;
set<ll>::iterator it2;
multiset<ll>::iterator it3;
for(i=;i<=n;i++){
scanf("%s%I64d",s,&v);
//printf(" i=%I64d s=%s v=%I64d\n",i,s,v);
if(s[]=='V'){
x.insert(v);
it=x.find(v);
it1=it2=it;
it1--;it2++;
l=*it1;
r=*it2;
le=r-l;
xp.erase(xp.find(le));
xp.insert(v-l);
xp.insert(r-v);
it3=xp.end();
it3--;
xmax=*it3;
//printf(" l=%I64d v=%I64d r=%I64d xmax=%I64d\n",l,v,r,xmax);
}
else{
y.insert(v);
it=y.find(v);
// printf(" *it=%I64d\n",*it);
it1=it2=it;
it1--;it2++;
l=*it1;
r=*it2;
le=r-l;
// printf(" *it1=%I64d *it2=%I64d le=%I64d\n",*it1,*it2,le);
yp.erase(yp.find(le));
yp.insert(v-l);
yp.insert(r-v);
it3=yp.end();
it3--;
ymax=*it3;
// printf(" *it3=%I64d\n",*it3);
// printf(" l=%I64d v=%I64d r=%I64d ymax=%I64d\n",l,v,r,ymax);
}
out();
}
} void out()
{
//printf(" xmax=%I64d ymax=%I64d\n",xmax,ymax);
printf("%I64d\n",xmax*ymax );
} int main()
{
//freopen("data.in","r",stdin);
//scanf("%d",&T);
//for(cnt=1;cnt<=T;cnt++)
while(scanf("%I64d%I64d%I64d",&w,&h,&n)!=EOF)
{
ini();
solve();
// out();
}
}
Codeforces Round #296 (Div. 2) C. Glass Carving [ set+multiset ]的更多相关文章
- Codeforces Round #296 (Div. 1) A. Glass Carving Set的妙用
A. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- 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自带的排序和查询.每次把对应的块拿出来分成两块 ...
随机推荐
- python+selenium(python基础)
1.编辑器的选择 好刀不误砍柴工,那么我们写代码也需要一个利器,虽然python自带有python shell ,但我们在执行代码的时候,需要开很多窗口,最重要的一点是,代码文件的管理很不方便,笔者推 ...
- Android掌中游斗地主游戏源码完整版
源码大放送-掌中游斗地主(完整版),集合了单机斗地主.网络斗地主.癞子斗地主等,有史以来最有参考价值的源码,虽然运行慢了一点但是功能正常,用的是纯java写的. 项目详细说明:http://andro ...
- 洛谷 P2680 运输计划
题目背景 公元 2044 年,人类进入了宇宙纪元. 题目描述 L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之间,这 n-1 条航道连通了 L 国的所有星球. 小 P 掌管一家 ...
- 51nod 1067 Bash游戏 V2
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 有一堆石子共有N个.A B两个人轮流拿,A先拿.每次只能拿1,3,4颗,拿到最后1颗石子的人获胜.假设A B都非常聪 ...
- fork后子进程从哪里开始执行
子进程和父进程都从调用fork函数的下一条语句开始执行
- 指针-动态开点&合并线段树
一个知识点不在一道题里说是没有灵魂的 线段树是用来处理区间信息的咯 但是往往因为需要4倍空间让许多人退却,而动态开点的线段树就非常棒 仿佛只用2倍就可以咯 指针保存位置,即节点信息,是很舒适的,所以用 ...
- 阿里云首次安装和部署nginx
1.执行yum命令安装依赖 yum -y install pcre* yum -y install openssl* 2.下载nginx //如果没有安装wget,下载已编译版本 yum instal ...
- 普通用户切换到root用户
普通用户切换到root用户首先按组合键 CTRL+ALT+T 进入终端界面,一般终端界面默认为普通用户权限模式,如何从普通用户进入root用户首先重置root密码输入 sudo passwd root ...
- MySQL丨03丨基本语句
MySQL语句都是以 ; 号结尾的 看库(刘大婶直接面对的是各种档案袋) show databases; 建库(新弄了一个档案袋) create database database_name; 删库( ...
- JS获取所有LI中第三个<SPAN>