CodeForces

来源:互联网 发布:com.cn域名注册 编辑:程序博客网 时间:2024/06/06 02:11

Glass Carving

Description:

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.

Example

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:
这里写图片描述


题目大意:
有一块长w宽h的玻璃,每次水平或垂直的切一刀。每做一次切割以后,输出当前的最大的玻璃面积。

解题思路:
1.由于都是水平或者垂直的切割,所有的玻璃都是长方形的,只要知道两条边的长度就可以知道面积了。
2.由于切割点不会重复,可以用set容器存储各个端点,并且set容器是自动有序。另外由于线段长度是会重复的,因此需要用Multiset容器存储各个线段长。
3.每做一次切割,就在相应方向的set中找到边界点,pos1-pos2可以得到线段长度,再回到相应的Multiset中找出边长删去,并将两个新的边长放回。

            it = h.find(num);            it++;            pos1 = *it;       //切割点 右边的端点            it--;  it--;            pos2 = *it;       //切割点 左边的端点

4.水平方向和竖直方向分开存储,每次分别取出最大的边长度相乘就得到了最大的玻璃面积。


源代码

#include<iostream>#include<string.h>#include<vector>#include<queue>#include<stack>#include<algorithm>#include<set>#include<map>using namespace std;set<int> v;set<int> h;multiset<int> dv;multiset<int> dh;set<int>::iterator it; int main() {    int Ver, Hor, times;    char cmd[2];    int num, i;    int pos1, pos2;    scanf("%d%d%d", &Ver, &Hor, &times);    v.insert(0);    h.insert(0);    v.insert(Ver);    h.insert(Hor);    dv.insert(Ver);    dh.insert(Hor);    for (i = 0; i < times; i++) {        scanf("%s%d", cmd, &num);        if (cmd[0] == 'H') {            h.insert(num);            it = h.find(num);            it++;            pos1 = *it;            it--;  it--;            pos2 = *it;            it = dh.find(pos1 - pos2);            dh.erase(it);            dh.insert(pos1-num);            dh.insert(num-pos2);        }        else {            v.insert(num);            it = v.find(num);            it++;            pos1 = *it;            it--;   it--;            pos2 = *it;            it = dv.find(pos1 - pos2);            dv.erase(it);            dv.insert(pos1-num);            dv.insert(num-pos2);        }        it = dv.end();        it--;        pos1 = *it;        it = dh.end();         it--;        pos2 =*it;        printf("%lld\n", (long long)pos1 * pos2);    }    return 0;}