int n; int a[N]; //存储每个数 int q[N]; //存储不同长度下上升子序列的结尾最小值,应该严格单调递增
intmain() { scanf("%d", &n); for (int i = 0; i < n; i ++ ) scanf("%d", &a[i]);
int len = 0;//存储当前的最大长度 for (int i = 0; i < n; i ++ ) { int l = 0, r = len; while (l < r) { int mid = l + r + 1 >> 1; if (q[mid] < a[i]) l = mid; else r = mid - 1; } len = max(len, r + 1); q[r + 1] = a[i]; }