C. Glass Carving (CF Round #296 (Div. 2) STL--set的运用)

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 wmm ?×? 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:

题意:一个w*h的玻璃,现在水平或竖直切n次(“H”表示水平切,“V”表示竖直切),每一次切后输出当前切成的块中的最大面积。

思路:用set记录切割的位置(要用两个set,分别来记录长和宽),multiset记录某一条边被切后 所得到的 小段的长度(也要两个,分别记录长和宽的)。那么每次切后就从multiset中取出最大的长和宽,相乘即得面积。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#define FRE(i,a,b)  for(i = a; i <= b; i++)
#define FRL(i,a,b)  for(i = a; i < b; i++)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define DBG         pf("Hi\n")
typedef __int64 ll;
using namespace std;

int w,h,n;
set<int>wxs;
set<int>hxs;
multiset<int>wds;
multiset<int>hds;

int main()
{
    int i,j;
    while (~sfff(w,h,n))
    {
        set<int>::iterator it,p;
        char s[3];
        int x;
        wxs.clear();
        hxs.clear();
        wds.clear();
        hds.clear();
        wxs.insert(0); wxs.insert(w);
        hxs.insert(0); hxs.insert(h);
        wds.insert(w); hds.insert(h);
        while (n--)
        {
            scanf("%s%d",s,&x);
            if (s[0]=='H')
            {
                it=hxs.lower_bound(x);
                p=it;
                p--;
                int dis = *it - *p;
                hds.erase(hds.find(dis));
                hds.insert(*it-x);
                hds.insert(x-*p);
                hxs.insert(x);
            }
            else
            {
                it=wxs.lower_bound(x);
                p=it;
                p--;
                int dis = *it - *p;
                wds.erase(wds.find(dis));
                wds.insert(*it-x);
                wds.insert(x-*p);
                wxs.insert(x);
            }
            int xx= *wds.rbegin();
            int yy= *hds.rbegin();
            pf("%I64d\n",(ll)xx * (ll)yy);  //最后要强制转化,不然会爆int
        }
    }
    return 0;
}
时间: 2024-08-13 11:25:50

C. Glass Carving (CF Round #296 (Div. 2) STL--set的运用)的相关文章

B. Error Correct System (CF Round #296 (Div. 2))

B. Error Correct System time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create

cf Round#273 Div.2

题目链接,点击一下 Round#273 Div.2 ================== problem A Initial Bet ================== 很简单,打了两三场的cf第一次在10分钟内过题 判平均数,且注意b为正 1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int res = 0,n; 6 for(int i = 0; i < 5; i++) 7 { 8 cin>>

Codeforces Round #296 (Div. 2) (ABCDE题解)

比赛链接:http://codeforces.com/contest/527 A. Playing with Paper time limit per test:2 seconds memory limit per test:256 megabytes One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm ?×? b mm sheet

Codeforces Round #Pi (Div. 2) (STL专场)

Codeforces Round #Pi (Div. 2) A - Lineland Mail 水题,拼手速. /* * @author Novicer * language : C++/C */ #include<iostream> #include<sstream> #include<fstream> #include<vector> #include<list> #include<deque> #include<queue

Codeforces Round #296 (Div. 2) C. 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 wmm  ×  h mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understa

【codeforces】【比赛题解】#854 CF Round #433 (Div.2)

cf一如既往挺丧 看丧题点我! [A]分数 Petya是数学迷,特别是有关于分数的数学.最近他学了所谓一个分数被叫做"真分数"当且仅当其分子小于分母,而一个分数被叫做"最简分数"当且仅当其分子分母互质.在闲暇时间,Petya在用计算器研究:如何把最简真分数转换为小数等问题.有一天他不小心把除号(÷)按成了加号(+),导致他得到了分子与分母的和.Petya想要得到他原来的分数,但他很快发现这不是唯一的.所以现在他想要知道最大的最简真分数使得其分子与分母的和为n. 输入

CF Round #354(Div.2)

A 输入一个数组,数组元素只能交换一次,求最大值与最小值之间的最大距离.(后来才发现看题目不认真,最小值为1,最大值为n...) #include<iostream> #include<cstring> #include<algorithm> using namespace std; int num[110]; int main() { int n; while(cin>>n) { int mmax=-1,mmin=10,maxflag=-1,minflag

【codeforces】【比赛题解】#849 CF Round #431 (Div.2)

cf的比赛越来越有难度了--至少我做起来是这样. 先看看题目吧:点我. 这次比赛是北京时间21:35开始的,算是比较良心. [A]奇数与结束 "奇数从哪里开始,又在哪里结束?梦想从何处起航,它们又是否会破灭呢?" 给定一个长度为n的序列.确定能不能将序列分成奇数个长度为奇数的非空字串,而且这其中每个子串以奇数开头,以奇数结尾.可以只分成一个(1也是奇数). 输入 第一行一个正整数n,表示序列长度. 第二行n个整数,表示序列中的元素. 输出 输出"Yes"或"

Codeforces Round #296 (Div. 2)——A long long——Playing with Paper

One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm  ×  b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by