2022-3-16
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
vector<PII> a;
vector<int> b;
int ans;
int main()
{
int n,p;scanf("%d",&n);
while(n--){int l,r;cin>>l>>r;a.push_back({l,r});}
sort(a.begin(),a.end());
for(int i=a.size()-1;i>=0;){
p = a[i].first;ans++,i--;
while(a[i].first<=p&&a[i].second>=p)i--;
}
printf("%d",ans);
return 0;
}
2024-11-19
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
struct info{
int l,r;
bool operator< (const info &y) const {
return l < y.l;
}
}sec[N];
int n;
int main(){
cin>>n;
for(int i = 1;i<=n;i ++)cin>>sec[i].l >> sec[i].r;
int tmp;
sort(sec+1,sec+1+n);
int ans = 0;
for(int i = n;i>=1;){
ans ++;
tmp = sec[i].l;
while(i && sec[i-1].r >= tmp)--i;
--i;
}
cout<<ans<<endl;
return 0;
}