2014年2月2日 星期日

[UVA] 11020 - Efficient Solutions


#include<stdio.h>
#include<string.h>
#include<set>
using namespace std;
struct P{
    int x,y;
    friend bool operator < (P a,P b){
        return a.x<b.x;
    }
};
multiset<P> _set;
multiset<P>::iterator it;
int main(){
    int t,n,x,y,C=0;
    scanf("%d",&t);
    while(t--){
        _set.clear();
        if(C) puts("");
        printf("Case #%d:\n",++C);
        scanf("%d",&n);
        while(n--){
            scanf("%d%d",&x,&y);
            it=_set.lower_bound((P){x,y});
            if(it==_set.begin() || (--it)->y>y){
                _set.insert((P){x,y});
                it=_set.upper_bound((P){x,y});
                while(it!=_set.end() && it->y>=y)
                    _set.erase(it++);
            }
            printf("%d\n",_set.size());
        }
    }
}

沒有留言:

張貼留言