提交时间:2024-03-30 15:54:38

运行 ID: 140570

#include<cstdio> #include<algorithm> using namespace std; int a[4000005]; int d[4000005]; int main() { int n; scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&a[i]); d[1]=a[1]; int len=1; for (int i=2;i<=n;i++) { if (a[i]>=d[len]) d[++len]=a[i]; else { int j=upper_bound(d+1,d+len+1,a[i])-d; d[j]=a[i]; } } printf("%d\n",len); return 0; }