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自带的排序和查询.每次把对应的块拿出来分成两块 ...
随机推荐
- PKU_campus_2017_K Lying Island
思路: 题目链接http://poj.openjudge.cn/practice/C17K/ 状压dp.dp[i][j]表示第i - k人到第i人的状态为j的情况下前i人中最多有多少好人. 实现: # ...
- P1309 瑞士轮 未完成 60
题目背景 在双人对决的竞技性比赛,如乒乓球.羽毛球.国际象棋中,最常见的赛制是淘汰赛和循环赛.前者的特点是比赛场数少,每场都紧张刺激,但偶然性较高.后者的特点是较为公平,偶然性较低,但比赛过程往往十分 ...
- 最新版kubernetesV1.14.1集群一键自动部署脚本
部署命令如下:详情及注意事项请看README.md git clone https://github.com/luckman666/deploy_Kubernetes-v1.14.1.git cd d ...
- UML建模图实战笔记
一.前言 UML:Unified Modeling Language(统一建模语言),使用UML进行建模的作用有哪些: 可以更好的理解问题 可以及早的发现错误或者被遗漏的点 可以更加方便的进行组员之间 ...
- python pandas 中 loc & iloc 用法区别
转自:https://blog.csdn.net/qq_21840201/article/details/80725433 ### 随机生DataFrame 类型数据import pandas as ...
- 初用emmet
下载emmet的pspad插件emmet.js.复制到pspad目录下的 script\JScript 文件夹. 输入 ul#nav>li.item$*4>{Item $} 但是没反应. ...
- Docker Hello World容器运行报错的解决办法
费了好大力气从Docker官网下载了Docker Community Editor的安装镜像,Docker.dmg, 总共将近500MB,双击进行安装: 命令行里使用docker version查看版 ...
- Uniform Resource Identifier
https://en.wikipedia.org/wiki/Uniform_Resource_Identifier "URI" redirects here. For othe ...
- CodeForces - 1059D——二分/三分
题目 题目链接 简单的说,就是作一个圆包含所有的点且与x轴相切,求圆的最小半径 方法一 分析:求最小,对半径而言肯定满足单调性,很容易想到二分.我们二分半径,然后由于固定了与X轴相切,我们对于每一个点 ...
- DROP TYPE - 删除一个用户定义数据类型
SYNOPSIS DROP TYPE name [, ...] [ CASCADE | RESTRICT ] DESCRIPTION 描述 DROP TYPE 将从系统表里删除用户定义的类型. 只有类 ...