总结: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;
}

相关文章:

  • 2021-05-29
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2021-11-15
猜你喜欢
  • 2022-12-23
  • 2022-03-05
  • 2022-01-11
  • 2021-09-27
  • 2021-09-13
  • 2021-11-02
  • 2022-02-19
相关资源
相似解决方案