区间数组

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n;
struct Range{
    int l,r;
    bool operator<(const Range & w)const 
    {
        return l<w.l;
    }
}range[N];
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        int l,r;
        cin>>l>>r;
        range[i]={l,r};
    }
    sort(range,range+n);
    priority_queue<int,vector<int>,greater<int>> heap;
        for (int i = 0; i < n; i ++ )
    {
        auto r = range[i];
        if (heap.empty() || heap.top() >= r.l) heap.push(r.r);
        else
        {
            heap.pop();
            heap.push(r.r);
        }
    }
    cout<<heap.size()<<endl;
    return 0;
}

 

 

posted @ 2023-05-23 20:09  艾鑫4646  阅读(5)  评论(0编辑  收藏  举报