区间合并
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 100010;
vector<pair<int, int>> nums, res;
int n;
int main() {
scanf("%d", &n);
int l, r;
for (int i = 0; i < n; i ++ ) {
scanf("%d%d", &l, &r);
nums.push_back({l, r});
}
//按左端点排序
sort(nums.begin(), nums.end());
int start = -2e9, end = -2e9;
for(auto item : nums) {
//情况1:无法合并
if (end < item.first) {
if (end != -2e9) res.push_back({l, r});
start = item.first;
end = item.second;
}
//情况2:可以合并
if (end >= item.first) {
if (end <= item.second) end = item.second;
}
}
res.push_back({start, end});
cout << res.size();
}