https://www.luogu.com.cn/problem/P1020
#include<bits/stdc++.h>
using namespace std;
int a[1000000],l[1000000];
int main()
{
int n=1,cnt=0,len1=1;
while(cin>>a[n]) n++;
n--;
l[++cnt]=a[1];
for(int i=2;i<=n;i++)
{
if(a[i]<=l[cnt])
{
len1++;
l[++cnt]=a[i];
}
else
{
int x=upper_bound(l+1,l+1+cnt,a[i],greater<int>())-l;
l[x]=a[i];
}
}
cout<<len1<<"
";
cnt=0;int len2=1;
l[++cnt]=a[1];
for(int i=2;i<=n;i++)
{
if(a[i]>l[cnt])
{
l[++cnt]=a[i];
len2++;
}
else
{
int x=lower_bound(l+1,l+1+cnt,a[i])-l;
l[x]=a[i];
}
}
cout<<len2;
return 0;
}```