Uva 11120 Efficient Solutions

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1961

本题题意是求每一次查询的优势的人数,我们可以用现成的multiset代替原本的平衡树。

mulitse可以存储相同的两个元素。排序方式可以自定义。

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <set>
using namespace std;

struct Point
{
    int x,y;
    Point(int _x,int _y)
    {
        x = _x;
        y = _y;
    }
    bool operator < (const Point & rhs) const
    {
        return x < rhs.x || (x == rhs.x && y < rhs.y);
    }
};
multiset<Point> S;
multiset<Point>::iterator it;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif
    int t;
    int n;
    int x,y;
    int cas = 0;
    scanf(" %d",&t);
    while(t--)
    {
        cas++;
        printf("Case #%d:\n",cas);
        S.clear();
        scanf(" %d",&n);
        for(int i=0;i<n;i++)
        {
            scanf(" %d %d",&x,&y);
            Point a(x,y);
            it = S.lower_bound(a);
            if(it == S.begin() || (--it)->y > y )
            {
                S.insert(a);
                it = S.upper_bound(a);
                while(it!=S.end() && it->y >= y)
                {
                    S.erase(it++);
                }
            }
            printf("%d\n",S.size());
        }
        if(t!=0) puts("");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值