传送门

C. Glass Carving
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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?

Input

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.

Output

After each cut print on a single line the area of the maximum available glass fragment in mm2.

Sample test(s)
Input
4 3 4
H 2
V 2
V 3
V 1
Output
8
4
4
2
Input
7 6 5
H 4
V 3
V 5
H 2
V 1
Output
28
16
12
6
4
Note

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 ]的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. CodeForces Round #296 Div.2

    A. Playing with Paper 如果a是b的整数倍,那么将得到a/b个正方形,否则的话还会另外得到一个(b, a%b)的长方形. 时间复杂度和欧几里得算法一样. #include < ...

  5. Codeforces Round #296 (Div. 1) E. Triangles 3000

    http://codeforces.com/contest/528/problem/E 先来吐槽一下,一直没机会进div 1, 马力不如当年, 这场题目都不是非常难,div 2 四道题都是水题! 题目 ...

  6. 字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System

    题目传送门 /* 无算法 三种可能:1.交换一对后正好都相同,此时-2 2.上面的情况不可能,交换一对后只有一个相同,此时-1 3.以上都不符合,则不交换,-1 -1 */ #include < ...

  7. 水题 Codeforces Round #296 (Div. 2) A. Playing with Paper

    题目传送门 /* 水题 a或b成倍的减 */ #include <cstdio> #include <iostream> #include <algorithm> ...

  8. 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 ...

  9. Codeforces Round #296 (Div. 2) A B C D

    A:模拟辗转相除法时记录答案 B:3种情况:能降低2,能降低1.不能降低分别考虑清楚 C:利用一个set和一个multiset,把行列分开考虑.利用set自带的排序和查询.每次把对应的块拿出来分成两块 ...

随机推荐

  1. sass 常用用法笔记

    最近公司开发的h5项目,需要用到sass,所以领导推荐让我去阮一峰大神的SASS用法指南博客学习,为方便以后自己使用,所以在此记录. 一.代码的重用 1.继承:SASS允许一个选择器,继承另一个选择器 ...

  2. JS编写自己的富文本编辑器

    富文本编辑器,网上有很多功能齐全种类丰富的如百度的Ueditor,简单适用型的如WangEditor等等.在经过一番挑选后,我发现都不适用现在的项目,然后决定自己造轮子玩玩.富文本编辑器中主要涉及到J ...

  3. Android 常见的工具类

    /** * Wifi 管理类 * * @author Administrator * 使用方法 * WifiManagerUtils wifiManager = new WifiManagerUtil ...

  4. mac及windows下安装ss实现***

    官网下载shadowsock(mac/windows都是下面地址,页面会根据当前系统自动判断所下载的包) https://sourceforge.net/projects/shadowsocksgui ...

  5. 安装nginx的一些注意事项

    1.如何彻底屏蔽掉Nginx的banner 为了安全或者某些个人的原因,如果要屏蔽掉nginx的banner,要修改以下几个位置: src/http/ngx_http_header_filter_mo ...

  6. 洛谷 P1021 邮票面值设计

    题目描述 给定一个信封,最多只允许粘贴N张邮票,计算在给定K(N+K≤15)种邮票的情况下(假定所有的邮票数量都足够),如何设计邮票的面值,能得到最大值MAX,使在1-MAX之间的每一个邮资值都能得到 ...

  7. vue 数组对接字符串 传值时候,join(',') 一下 watch

    vue 数组对接字符串 传值时候,join(',') 一下 watch watch: { 'tFill.otherDescArr': function (newVal, oldVal) { this. ...

  8. LinkdList和ArrayList异同、实现自定义栈

    //.LinkdList和ArrayList异同 //ArrayList以连续的空间进行存储数据 //LinkedList以链表的结构存储数据 //栈 先进后出 最上面是栈顶元素 arrayLiat自 ...

  9. python基础一 day3 列表

    字符串是有序的,列表也是有序的,有索引值,可以切片 可以用切片来截取列表中的任何部分返回得到一个新列表. 列表方法: 1:增加 结果: 例子:    结果: int类型不可迭代      结果: 删: ...

  10. 关于Java的三种普通排序

    首先要知道是哪几种排序 这里我们所说的是 冒泡排序,选择排序以及插入排序 然后要理解大概的排序速度 : 插入<选择<冒泡 下面是代码 大家可以拷贝自己在java环境里运行运行! publi ...