Monday, 28 September 2015

****(vvi) Glass Carvin

 Glass Carvin

http://codeforces.com/problemset/problem/527/C

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 0001 ≤ 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:


--------------------------------------------------------------------------------------------------------------------------------------------
At any moment we realise that the maximum area is the product of the segment produced my max vertical length and maximum height 
We keep 4 sets that represent the following (1) Cuts at horizontal (2) Cuts at vertical (3) Length of vetical segments (4) width of horizontal segment initiall we push (0,w) to height and (0,h) to vertical then we push h to horizontal size array and w to vertical size array now when we make a cut horizontally clearly imagine the things taking place Suppose we cut at dist d (1) we try to find the position of the cut between to last cuts(initially it is between 0 and h) (2) we remove the piece (h-0) from the set that represents horizontal cut lengths(segments) (3) We insert two new segment of length (d1-0) & (h-d1) to the segments. Thus we see we are simulating the process taking place . The maximum are can be found by product of maximum horizontal length and maximum vertical length




---------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include<bits/stdc++.h> using namespace std; #define ll long long int int main() { int n; int w,h; cin>>w>>h>>n; multiset<int> cuth,cutw,maxh,maxw; cuth.insert(0); cuth.insert(h); cutw.insert(0); cutw.insert(w); maxh.insert(h); maxw.insert(w); int len; for(int i=0;i<n;i++) { char str[10]; cin>>str; cin>>len; if(str[0]=='H') { // cout<<"t 1 "<<endl; multiset<int>:: iterator it,it1,it2; it=cuth.lower_bound(len); // cout<<*it<<endl; it1=it; it1--; int val=*it-*it1; // cout<<"del "<<val<<endl; it2=maxh.lower_bound(val); maxh.erase(it2); cuth.insert(len); maxh.insert((len-*it1)); maxh.insert((*it-len)); } else { multiset<int>:: iterator it,it1,it2; it=cutw.lower_bound(len); it1=it; it1--; int val=*it-*it1; // cout<<"del val "<<val<<endl; it2=maxw.lower_bound(val); maxw.erase(it2); cutw.insert(len); maxw.insert((len-*it1)); maxw.insert((*it-len)); } //cout<<"done "<<endl; ll l1=*(maxw.rbegin()); ll l2=*(maxh.rbegin()); //cout<<l1<<" "<<l2<<endl; ll ans=l1*l2; cout<<ans<<endl; } return 0; }

No comments:

Post a Comment