提交时间:2024-03-30 15:59:41

运行 ID: 140584

#include<bits/stdc++.h> using namespace std; int a[100005],n,dp[100005],top=0; int g(int x){ int l=1,r=top,res=0; while(l<=r){ int mid=(l+r)/2; if(x<dp[mid]){ 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]>=dp[top])dp[top+1]=a[i],top++; else dp[g(a[i])]=a[i]; } cout<<top<<endl; }