提交时间:2022-07-19 12:39:20
运行 ID: 52530
#include <bits/stdc++.h> using namespace std; struct node { int s, t; bool operator<(const node& x) const { return ((t == x.t) ? (s < x.s) : (t > x.t)); } } a[500005]; int n; int s[500005]; int f[500005]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &a[i].s, &a[i].t); // s[i] = a[i].s; } sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) { s[i] = a[i].s; } f[0] = 0; for (int i = 1; i <= n; i++) { f[i] = max(f[i - 1], f[lower_bound(s + 1, s + i, a[i].s) - s - 1] + 1); } printf("%d\n", f[n]); return 0; }