Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

按右端点排序的

Posted by 1851494 at 2022-04-14 22:09:19 on Problem 1009
#include<queue>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;

struct Node {
    int l, r, id;
    bool operator<(const Node&rhs) const{
        if(r!=rhs.r)return r<rhs.r;
        return l<rhs.l;
    }
}a[200066];

int n;
multiset<pair<int, int> >Set;
int pos[50060];

int main()
{
    while(scanf("%d", &n)==1){
        for (int i = 1; i <= n; i++)
        {
            scanf("%d%d", &a[i].l, &a[i].r);
            a[i].id=i;
        }
        sort(a+1, a+n+1);
        int tot=0;
        for(int i=1; i<=n; i++){
            if(Set.size()==0||(*Set.begin()).first>=a[i].l){
                Set.insert(make_pair(a[i].r, ++tot));
                pos[a[i].id]=tot;
            }else {
                multiset<pair<int, int> >::iterator it=Set.upper_bound(make_pair(a[i].l, 0));
                --it;
                int p=(*it).second;
                Set.erase(it);
                Set.insert(make_pair(a[i].r, p));
                pos[a[i].id]=p;
            }
        }
        printf("%d\n", (int)Set.size());
        for(int i=1; i<=n; i++) printf("%d\n", pos[i]);
    }
    
    return 0;
}

/*

5
1 2
4 5
6 7
8 9
3 10


*/

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator