提交时间:2024-03-30 14:43:35

运行 ID: 140372

#include<iostream> using namespace std; const int N = 1e5 + 10; int n, a[N], f[N], idx = 0; int f1(int x){ int l = 1, r = idx, ret = 0; while(l <= r){ int mid = (l + r) / 2; if(x <= f[mid]){ l = mid + 1; ret = mid; } else{ r = mid - 1; } } return ret; } int main(){ cin >> n; for(int i = 0; i < n; i++){ cin >> a[i]; } f[0] = -1e9; for(int i = 0; i < n; i++){ if(a[i] >= f[idx]) f[idx+1] = a[i], idx++; else f[f1(a[i])] = a[i]; } cout << idx; return 0; }