Glass Carving

time limit per test

2 seconds

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.

Examples
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:

 
利用set的有序性
#include <bits/stdc++.h>
#include <cstdio>
#include <set>
using namespace std;
set<int>H,V;
int mh[],mv[];
int n,h,v,x,maxh,maxv;
char op;
void cut(set<int>& s,int *a,int val)
{
s.insert(val);
set<int>::iterator l,r;
l=r=s.find(val);
l--,r++;
a[*r-*l]--;
a[*r-val]++;
a[val-*l]++;
}
int main()
{
scanf("%d%d%d",&v,&h,&n);
memset(mh,,sizeof(mh));
memset(mv,,sizeof(mv));
mh[h]=,mv[v]=;
H.insert(h),V.insert(v);
H.insert(),V.insert();
maxh=h,maxv=v;
while(n--)
{
cin>>op>>x;
op=='H'?cut(H,mh,x):cut(V,mv,x);
while(!mh[maxh])maxh--;
while(!mv[maxv])maxv--;
printf("%lld\n",(long long)maxh*maxv);
}
return ;
}
 

最新文章

  1. Windows远程桌面打印机映射
  2. js关闭子窗口,刷新父窗口
  3. 验证坐标在某片坐标区域内 php 代码
  4. python_way day17 html-day3 前端插件(fontawsome,easyui,bootstrap,jqueryui,bxslider,jquerylazyload),web框架
  5. 如何使div左右倾斜
  6. Effective C++ 总结(二)
  7. Debugging Failed Because Integrated Windows Authentication Is Not Enabled
  8. HDU 1796 Howmany integers can you find (容斥原理)
  9. 推荐系统相关算法:SVD
  10. 波折yosemite下载过程
  11. 软件开发常用的linux命令心得(ubuntu为例)
  12. hadoop多文件格式输入
  13. 【转】LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
  14. delphi idhttp post 普通提交乱码处理
  15. asp.net core 中间件应用
  16. 四:DRF项目开发的准备
  17. Maven学习 四 Eclipse与Maven结合的配置
  18. Android-Java-synchronized同步代码块的使用场景
  19. 在eclipse-oxygen-sts中,关于快捷键[CTRL + SHIFT + O]失效的问题
  20. codeforces 792D - Paths in a Complete Binary Tree

热门文章

  1. cocos2d-x 2.2.2 在lua中更换CCSprite的图片
  2. CDOJ 876 爱管闲事 DP
  3. iOS学习必须了解的七大手势
  4. nyoj--214--单调递增子序列(二)(二分查找+LIS)
  5. POJ 1952 DP
  6. Codeforces 988E. Divisibility by 25
  7. POJ 3255 Roadblocks (Dijkstra求最短路径的变形)(Dijkstra求次短路径)
  8. Caffe学习--Net分析
  9. IPv6第二层寻址,IPv6接口要求
  10. JS自定义全局Error