抱歉,稍微有点标题党。。。。。。
本人尝试用STL,发现用upper_bound时子任务1过不了,更换了lower_bound后全AC了,但不太明白为什么。请问有没有哪位大佬解释一下。
感谢!!!!!
成功AC的代码如下,失败的程序就是把里面的lower_bound替换成upper_bound。
#include<bits/stdc++.h>
using namespace std;
int *a,n,*b,len;
int main()
{
scanf("%d",&n);len=1;
a=new int[n+1];b=new int[n+1];
memset(b,0,sizeof(b));
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
b[len]=a[1];
for(int i=2;i<=n;i++)
{
if(a[i]>b[len])
b[++len]=a[i];
else
b[lower_bound(b+1,b+len+1,a[i])-b]=a[i];
}
printf("%d",len);
return 0;
}