Accepted
/in/foo.cc: In function 'int LIS()': /in/foo.cc:28:19: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized] f[ans]=a[i]; ~~~~~~^~~~~
代码
#include <bits/stdc++.h>
using namespace std;
int a[100005],f[100005],n;
int LIS()
{
memset(f,0,sizeof(f));
int l,r,mid;
int p=0,ans;
f[++p]=a[1];
for(int i=2;i<=n;i++)
{
if(f[p]<a[i]) f[++p]=a[i];
else
{
l=1;
r=p;
while(l<=r)
{
mid=(l+r)>>1;
if(f[mid]>=a[i])
{
ans=mid;
r=mid-1;
}
else l=mid+1;
}
f[ans]=a[i];
}
}
return p;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
cout<<LIS();
}