提交时间:2024-03-30 15:34:16
运行 ID: 140471
#include<iostream> using namespace std; const int N = 1e5 + 10; int n, a[N], f[N], top = 0; int g(int x){ int l = 1, r = top, res = 0; while(l <= r){ int mid = (l + r) / 2; if(x < f[mid]){ r = mid - 1; res = mid; } else{ l = mid + 1; } } return res; } int main(){ cin >> n; for(int i = 0; i < n; i++){ cin >> a[i]; } for(int i = 0; i < n; i++){ if(a[i] >= f[top]) f[top+1] = a[i], top++; else f[g(a[i])] = a[i]; } // for(int i = 1; i <= top; i++) cout << f[i] << ' '; cout << top; return 0; }