传送门

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 4H 2V 2V 3V 1

Output
8442

Input
7 6 5H 4V 3V 5H 2V 1

Output
28161264

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记录割出来的块的大小

  1 #include <cstdio>
  2 #include <cstring>
  3 #include <stack>
  4 #include <vector>
  5 #include <algorithm>
  6 #include <queue>
  7 #include <map>
  8 #include <string>
  9 #include <set>
 10
 11 #define ll long long
 12 int const N = 200005;
 13 int const M = 205;
 14 int const inf = 1000000000;
 15 ll const mod = 1000000007;
 16
 17 using namespace std;
 18
 19 ll w,h,n;
 20 set<ll> x;
 21 set<ll> y;
 22 multiset<ll> xp;
 23 multiset<ll> yp;
 24 ll xmax,ymax;
 25
 26 void out();
 27
 28 void ini()
 29 {
 30     x.clear();y.clear();xp.clear();yp.clear();
 31     x.insert(0);x.insert(w);
 32     y.insert(0);y.insert(h);
 33     xp.insert(w);yp.insert(h);
 34     xmax=w;ymax=h;
 35    // out();
 36 }
 37
 38 void solve()
 39 {
 40     ll i;
 41     char s[2];
 42     ll v;
 43     ll r,l;
 44     ll le;
 45     set<ll>::iterator it;
 46     set<ll>::iterator it1;
 47     set<ll>::iterator it2;
 48     multiset<ll>::iterator it3;
 49     for(i=1;i<=n;i++){
 50         scanf("%s%I64d",s,&v);
 51         //printf(" i=%I64d s=%s v=%I64d\n",i,s,v);
 52         if(s[0]=='V'){
 53             x.insert(v);
 54             it=x.find(v);
 55             it1=it2=it;
 56             it1--;it2++;
 57             l=*it1;
 58             r=*it2;
 59             le=r-l;
 60             xp.erase(xp.find(le));
 61             xp.insert(v-l);
 62             xp.insert(r-v);
 63             it3=xp.end();
 64             it3--;
 65             xmax=*it3;
 66             //printf(" l=%I64d v=%I64d r=%I64d xmax=%I64d\n",l,v,r,xmax);
 67         }
 68         else{
 69             y.insert(v);
 70             it=y.find(v);
 71            // printf("  *it=%I64d\n",*it);
 72             it1=it2=it;
 73             it1--;it2++;
 74             l=*it1;
 75             r=*it2;
 76             le=r-l;
 77           //  printf("  *it1=%I64d *it2=%I64d le=%I64d\n",*it1,*it2,le);
 78             yp.erase(yp.find(le));
 79             yp.insert(v-l);
 80             yp.insert(r-v);
 81             it3=yp.end();
 82             it3--;
 83             ymax=*it3;
 84            // printf("  *it3=%I64d\n",*it3);
 85            // printf(" l=%I64d v=%I64d r=%I64d ymax=%I64d\n",l,v,r,ymax);
 86         }
 87         out();
 88     }
 89 }
 90
 91 void out()
 92 {
 93     //printf(" xmax=%I64d ymax=%I64d\n",xmax,ymax);
 94     printf("%I64d\n",xmax*ymax );
 95 }
 96
 97 int main()
 98 {
 99     //freopen("data.in","r",stdin);
100     //scanf("%d",&T);
101     //for(cnt=1;cnt<=T;cnt++)
102     while(scanf("%I64d%I64d%I64d",&w,&h,&n)!=EOF)
103     {
104         ini();
105         solve();
106        // out();
107     }
108 }

转载于:https://www.cnblogs.com/njczy2010/p/4350016.html

Codeforces Round #296 (Div. 2) C. Glass Carving [ set+multiset ]相关推荐

  1. Codeforces Round #296 (Div. 1) D. Fuzzy Search FFT匹配字符串

    传送门 文章目录 题意: 思路: 题意: n,m,k≤2e5n,m,k\le2e5n,m,k≤2e5 思路: 直接考虑fftfftfft来匹配字符串. 由于kkk是给定的,所以难度低了很多,普通的字符 ...

  2. Codeforces Round #296 (Div. 2)

    第一次做CF,唉,还是基础的东西做的太少,练得不够. A.Playing with Paper 一个折纸游戏,大概意思就是从一个矩形中最多能切割出多少个大小可以不等的正方形. 已知长和宽a,b,不停地 ...

  3. Codeforces Round #296 (Div. 2) E. Data Center Drama (欧拉路)

    题目链接 题面: 题意: 给定一张无向连通图,你需要添加最少的边并且给每条边定向使得每个点的入度和出度都是偶数. into groups of two 一度在纠结是分成两组,还是每组两个..... 导 ...

  4. Codeforces Round #691 (Div. 1)

    Codeforces Round #691 (Div. 1) 题号 题目 知识点 A Row GCD 思维 B Glass Half Spilled 背包问题 C Latin Square 思维 D ...

  5. Codeforces Round #691 (Div. 2)

    Codeforces Round #691 (Div. 2) 题号 题目 知识点 A Red-Blue Shuffle 签到 B Move and Turn (规律结论题) C Row GCD 思维 ...

  6. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  7. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  8. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  9. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

最新文章

  1. Scrapy爬虫及案例剖析
  2. Python计算数据相关系数(person、Kendall、spearman)
  3. VC++ 打开文件夹,保存文件等对话框的调用
  4. ArchiCAD 23中文版
  5. C#方法中的反射方式和委托方式(小实例)
  6. 006-筛选分类排序搜索查找Filter-Classificatio-Sort-Search-Find-Seek-Locate
  7. Ubuntu 14.04 配置caffe环境
  8. sql azure 语法_Azure SQL Server中的CREATE DATABASE语句概述
  9. document.execCommand() 命令详解 只支持IE
  10. 第二百零二节,jQuery EasyUI,Layout(布局)组件
  11. 学c语言和51单片机的作业,《手把手教你学51单片机(C语言版)》例程和源码
  12. CrossApp 设置App启动页(无任何黑屏白屏,显示完启动画面之间到显示出首页界面)
  13. 加速度及陀螺仪传感器BMI160
  14. gif转换成jpg,这个方法很简单
  15. mqtt 3.1 php代码,MQTT V3.1
  16. linux 系统qcow2镜像制作
  17. HTML语言全称叫超文本标记语言,其中的“标记“如何理解,“超文本”又如何理解?
  18. Matlab傅里叶级数展开(附结果图)
  19. 2022年语音合成(TTS)和语音识别(ASR)年度总结
  20. 计算机考研零基础英语怎么复习,英语零基础怎么考研 上岸学姐来教你

热门文章

  1. 毕业5年跳槽24次,为什么这届95后换工作越来越勤?
  2. 半导体八大工艺流程图_半导体之光刻胶,看五大龙头谁能迈出国产化第一步?...
  3. 电脑有回声_Soundop下载-Soundop正式电脑版
  4. python读取txt文件存储数组_python – 从文本文件中将数据读入numpy数组
  5. php广告屏如何同步,户外LED大屏广告如何投放才能更吸引人?
  6. SQUEEZENET: ALEXNET-LEVEL ACCURACY WITH 50X FEWER PARAMETERS AND 0.5MB MODEL SIZE
  7. Numpy的使用(4)
  8. java如何多表断网,java Web如何离线使用并进行数据同步
  9. gerber文件怎么导贴片坐标_SMT贴片加工有哪些常用的名词
  10. alter table 加多个字段_Vue 组件设计 - table不需要封装