/ Randle /

记录详情

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];
             ~~~~~~^~~~~
# 状态 耗时 内存占用
#1 Accepted 5ms 760.0 KiB
#2 Accepted 4ms 752.0 KiB
#3 Accepted 3ms 752.0 KiB
#4 Accepted 4ms 768.0 KiB
#5 Accepted 6ms 748.0 KiB
#6 Accepted 5ms 728.0 KiB
#7 Accepted 7ms 760.0 KiB
#8 Accepted 43ms 992.0 KiB
#9 Accepted 66ms 1.125 MiB
#10 Accepted 69ms 1.098 MiB

代码

#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();
}

信息

递交者
类型
递交
题目
序 T2
题目数据
下载
语言
C++
递交时间
2017-10-19 20:03:22
评测时间
2017-10-19 20:03:22
评测机
分数
100
总耗时
216ms
峰值内存
1.125 MiB