1.求不下降就把上升序列中的lowerbound改成upperbound 即可(模版注意下标)
2.最多需要多少,每次lowerbound贪心即可(若未找到会返回末尾位置,建议数组0开始)
变量该局部局部全局全局 方便不易错 影响不大
#include<iostream>
#include<cstring>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=0x7f7f7f7f;
const int nn=1e5+50;
const double eps=1e-6;
inline int read() {
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x*f;
}
inline void write(int x) {
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
int a[100005],b[100005],c[100005];
int main ()
{
int cnt=0;
while(cin>>a[cnt])
{
cnt++;
}
cnt--;
for(int i=0;i<=cnt+1;++i)
{
c[i]=inf;
}
int ans=0;
for(int i=cnt;i>=0;--i)
{
int j=upper_bound(c,c+cnt+1,a[i])-c;
c[j]=a[i];
ans=max(ans,j+1);
}
cout<<ans<<endl;
int sum=0;
if(cnt==0)
{
cout<<0;
return 0;
}
b[sum++]=a[0];
for(int i=1;i<=cnt;++i)
{
int j=lower_bound(b,b+sum,a[i])-b;
if(j==sum)
{
b[sum++]=a[i];
}
else {
b[j]=a[i];
}
}
cout<<sum;
return 0;
}