803. 区间合并Acwing

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n;
int l,r;
typedef pair<int,int>PII;
vector<PII>ses;
void m(vector<PII>&segs){
    vector<PII>res;
    int st=-2e9;
    int ed=-2e9;
    for(auto se:segs){
        if(ed<se.first){
               if(st!=-2e9){res.push_back({st,ed});}
            st=se.first;ed=se.second;
        }
        else
            ed=max(ed,se.second);
    }
    res.push_back(st,ed);
    ses=res;
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>l>>r;
        ses.push_back({l.r})
    }
    sort(ses.begin(),ses.end());
    m(ses);
    cout<<ses.size();
    return 0;
}

 

posted @ 2022-10-29 22:08  山海自有归期  阅读(21)  评论(0编辑  收藏  举报