提交时间:2024-03-30 15:35:17
运行 ID: 140477
#include<bits/stdc++.h> using namespace std; const int Maxn=10001; int a[Maxn],f[Maxn],g[Maxn]; int n,top=0; int f1(int x) { int l=1,r=top,res=0; while (l<=r) { int mid=(l+r)/2; if (f[mid]>x) { r=mid-1; res=mid; } else { l=mid+1; } } return res; } int main() { cin>>n; for (int i=1;i<=n;i++) { cin>>a[i]; } for (int i=1;i<=n;i++) { if (a[i]>=f[top]) { f[top+1]=a[i]; top++; } else f[f1(a[i])]=a[i]; } cout<<top<<endl; return 0; }