【nlogn LIS】 模板

总结:stl真好用

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100100;
int a[maxn], n, lis[maxn], len;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i = 1; i <= n; i++) cin>>a[i];
	lis[++len] = a[1];
	for(int i = 2; i <= n; i++)
	{
		if(a[i] > lis[len])
			lis[++len] = a[i];
		else
		{
			int pos = lower_bound(lis+1, lis+1+len, a[i])-lis;
			lis[pos] = a[i];
		}
	}
	for(int i = 1; i <= len; i++) cout<<lis[i]<<" ";
	cout<<endl;
	cout<<len;
	return 0;
}
posted @ 2018-10-15 20:11  Misaka_Azusa  阅读(219)  评论(0编辑  收藏  举报
Live2D