总结:stl真好用
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100100;
int a[maxn], n, lis[maxn], len;
int main()
{
ios::sync_with_stdio(false);
cin>>n;
for(int i = 1; i <= n; i++) cin>>a[i];
lis[++len] = a[1];
for(int i = 2; i <= n; i++)
{
if(a[i] > lis[len])
lis[++len] = a[i];
else
{
int pos = lower_bound(lis+1, lis+1+len, a[i])-lis;
lis[pos] = a[i];
}
}
for(int i = 1; i <= len; i++) cout<<lis[i]<<" ";
cout<<endl;
cout<<len;
return 0;
}