博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #296 (Div. 2) C. Glass Carving [ set+multiset ]
阅读量:7083 次
发布时间:2019-06-28

本文共 4113 字,大约阅读时间需要 13 分钟。

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:
2015-03-19 07:09:30 GNU C++ Accepted 389 ms 12556 KB

 

题解:用两个set记录割点位置,用两个multiset记录割出来的块的大小

 

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
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
x; 21 set
y; 22 multiset
xp; 23 multiset
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
::iterator it; 46 set
::iterator it1; 47 set
::iterator it2; 48 multiset
::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

你可能感兴趣的文章
API相关基础知识
查看>>
黑马程序员-面向对象-07天-1 (抽象类描述)
查看>>
1106JS循环
查看>>
FreeBSD从零开始---安装后配置(一)
查看>>
PHP Ajax 跨域问题最佳解决方案
查看>>
Linux之开源软件移植
查看>>
C#.NET SQLite自适应32位/64位系统
查看>>
stl本子
查看>>
浅谈大型网站动态应用系统架构(转)
查看>>
iOS 日期时间控件
查看>>
ABAP 四舍五入函数
查看>>
JDBC使用步骤分哪几步?
查看>>
线段树心得
查看>>
Linux 进程间通信 信号灯集
查看>>
Python Day 8: html 基本知识
查看>>
2012年4月19日
查看>>
UVA 11090 Going in Cycle!! 二分答案 + bellman-ford
查看>>
final,static,super,this
查看>>
LeetCode解题思路:442. Find All Duplicates in an Array
查看>>
解决BCG库示例程序中的一个诡异编译错误
查看>>