codeforces 527C:STL set

x和y各用一个set保存切割点

L[k] H[k]记录长度为k的线段有几个

每添加一个切点,更新L[] H[],然后找到各找到最大值,相乘就是答案

关键是学学set的使用

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include"cstdio"
#include"queue"
#include"cmath"
#include"stack"
#include"iostream"
#include"algorithm"
#include"cstring"
#include"queue"
#include"map"
#include"set"
#include"vector"
#define ll long long
#define mems(a,b) memset(a,b,sizeof(a))
#define ls pos<<1
#define rs pos<<1|1

using namespace std;
const int MAXN = 200500;
const int MAXE = 200500;
const int INF = 0x3f3f3f3f;

set<int> h,v;
int L[MAXN],H[MAXN];

int main(){
    int x,y,n,ch=0,cv=0;
    scanf("%d%d%d",&y,&x,&n);
    mems(L,0);
    mems(H,0);
    h.insert(0);v.insert(0);
    h.insert(x);v.insert(y);
    int mxx=x,mxy=y;
    L[x]=H[y]=1;
    for(int i=0;i<n;i++){
        char arr[5];
        int t;
        set<int>::iterator l,r,mid;
        scanf("%s %d",arr,&t);
        if(arr[0]=='H'){
            h.insert(t);
            l=r=mid=h.find(t);
            l--;r++;
            L[*r-*l]--;
            L[*r-*mid]++;
            L[*mid-*l]++;
            if(!L[mxx]) while(!L[mxx]) mxx--;
        }
        else{
            v.insert(t);
            l=r=mid=v.find(t);
            l--;r++;
            H[*r-*l]--;
            H[*r-*mid]++;
            H[*mid-*l]++;
            if(!H[mxy]) while(!H[mxy]) mxy--;
        }
        //cout<<mxx<<'\t'<<mxy<<endl;
        printf("%I64d\n",(ll)mxx*mxy);
    }
    return 0;
}

 

posted @ 2016-01-17 18:59  Septher  阅读(166)  评论(0编辑  收藏  举报