题解:维护出一个最长非递增子序列,另外一个维护出一个最长递增子序列(不能证明,想想也有点道理),这个题坑点好多,终于体会到了二分真的很玄学,希望早日搞懂。
还有一个月徐州区域赛,一定要拿点东西回来啊,希望我呢,再不辜负每个人,也不辜负自己。
附上代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn=100050;
int s[maxn];
int l[maxn];
int b[maxn];
int main()
{
int temp,cnt=0;
while(scanf("%d",&temp)!=EOF){
s[cnt++]=temp;
}
int length=1;
for(int i=cnt-1;i>=0;i--){
if(l[length-1]<=s[i]){
l[length++]=s[i];
}else{
*upper_bound(l,l+length,s[i])=s[i];
}
}
cout<<length-1<<endl;
int llen=1;
for(int i=0;i<cnt;i++){
if(b[llen-1]<s[i]){
b[llen++]=s[i];
}else{
*lower_bound(b,b+llen,s[i])=s[i];
}
}
cout<<llen-1<<endl;
return 0;
}