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

來源:互聯網
上載者:User

標籤:glass carving   cf round #296 div. 2   

C. Glass Carvingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard 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 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:

題意:一個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;}



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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.