2 seconds
256 megabytes
standard input
standard output
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?
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.
After each cut print on a single line the area of the maximum available glass fragment in mm2.
4 3 4
H 2
V 2
V 3
V 1
8
4
4
2
7 6 5
H 4
V 3
V 5
H 2
V 1
28
16
12
6
4
Picture for the first sample test:
Picture for the second sample test:
10344839 | 2015-03-19 07:09:30 | njczy2010 | C - Glass Carving | GNU C++ | Accepted | 389 ms | 12556 KB |
题解:用两个set记录割点位置,用两个multiset记录割出来的块的大小
#include <cstdio>
#include <cstring>
#include <stack>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <set> #define ll long long
int const N = ;
int const M = ;
int const inf = ;
ll const mod = ; using namespace std; ll w,h,n;
set<ll> x;
set<ll> y;
multiset<ll> xp;
multiset<ll> yp;
ll xmax,ymax; void out(); void ini()
{
x.clear();y.clear();xp.clear();yp.clear();
x.insert();x.insert(w);
y.insert();y.insert(h);
xp.insert(w);yp.insert(h);
xmax=w;ymax=h;
// out();
} void solve()
{
ll i;
char s[];
ll v;
ll r,l;
ll le;
set<ll>::iterator it;
set<ll>::iterator it1;
set<ll>::iterator it2;
multiset<ll>::iterator it3;
for(i=;i<=n;i++){
scanf("%s%I64d",s,&v);
//printf(" i=%I64d s=%s v=%I64d\n",i,s,v);
if(s[]=='V'){
x.insert(v);
it=x.find(v);
it1=it2=it;
it1--;it2++;
l=*it1;
r=*it2;
le=r-l;
xp.erase(xp.find(le));
xp.insert(v-l);
xp.insert(r-v);
it3=xp.end();
it3--;
xmax=*it3;
//printf(" l=%I64d v=%I64d r=%I64d xmax=%I64d\n",l,v,r,xmax);
}
else{
y.insert(v);
it=y.find(v);
// printf(" *it=%I64d\n",*it);
it1=it2=it;
it1--;it2++;
l=*it1;
r=*it2;
le=r-l;
// printf(" *it1=%I64d *it2=%I64d le=%I64d\n",*it1,*it2,le);
yp.erase(yp.find(le));
yp.insert(v-l);
yp.insert(r-v);
it3=yp.end();
it3--;
ymax=*it3;
// printf(" *it3=%I64d\n",*it3);
// printf(" l=%I64d v=%I64d r=%I64d ymax=%I64d\n",l,v,r,ymax);
}
out();
}
} void out()
{
//printf(" xmax=%I64d ymax=%I64d\n",xmax,ymax);
printf("%I64d\n",xmax*ymax );
} int main()
{
//freopen("data.in","r",stdin);
//scanf("%d",&T);
//for(cnt=1;cnt<=T;cnt++)
while(scanf("%I64d%I64d%I64d",&w,&h,&n)!=EOF)
{
ini();
solve();
// out();
}
}