题目:
http://codeforces.com/contest/527/problem/C
题意:
求出在一个w, h (2 ≤ w, h ≤ 200 000)矩形中进行n(1 ≤ n ≤ 200 000)次横切或竖切操作之后得到的最大面积的矩阵.
思路:
set大法.
multiset<int> H, W, nh, nv;nh :记录每一次横切操作; nw: 记录每一次竖切操作.
H:记录得到的横边; W:记录得到的竖边.
H.erase(H.find(*n2 - *n1)); 此操作很好的降低了时间复杂度:)AC.
#include <iostream>
#include <cstdio>
#include <set>
#include <algorithm>
#include <cstring>
using namespace std;
int w, h, n;
multiset<int> H, W, nh, nv;
void init()
{
H.clear(); W.clear();
H.insert(h);
W.insert(w);
nh.clear(); nv.clear();
nh.insert(0); nv.insert(0);
nh.insert(h); nv.insert(w);
}
int main()
{
//freopen("in", "r", stdin);
while(~scanf("%d %d %d", &w, &h, &n)) {
int a, ans1, ans2;
char s[2];
init();
multiset<int>::iterator n1, n2;
while(n--) {
getchar();
scanf("%s%d", s, &a);
if(s[0] == 'H') {
n2 = nh.upper_bound(a);
n1 = (--n2);
n2++;
H.erase(H.find(*n2 - *n1));
H.insert(*n2 - a);
H.insert(a - *n1);
ans1 = *(--H.end()); ans2 = *(--W.end());
printf("%I64d\n", 1LL*ans1*ans2);
nh.insert(a);
}
if(s[0] == 'V') {
n2 = nv.upper_bound(a);
n1 = (--n2);
n2++;
W.erase(W.find(*n2 - *n1));
W.insert(*n2 - a);
W.insert(a - *n1);
ans1 = *(--H.end()); ans2 = *(--W.end());
printf("%I64d\n", 1LL*ans1*ans2);
nv.insert(a);
}
}
}
return 0;
}