提交时间:2022-07-19 14:44:23
运行 ID: 52617
#include <bits/stdc++.h> using namespace std; struct node { int s, t; bool operator<(const node& x) const { return ((s == x.s) ? (t > x.t) : (s < x.s)); } } a[500005]; int n; int t[500005]; int f[500005], longest; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &a[i].s, &a[i].t); } sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) { t[i] = a[i].t; } f[1] = t[1]; longest = 1; for (int i = 2; i <= n; i++) { if (t[i] <= f[longest]) f[++longest] = t[i]; else { *upper_bound(f + 1, f + longest + 1, t[i], greater<int>()) = t[i]; } } printf("%d\n", longest); return 0; }