题目链接

最长上升子序列O(n*log(n))的做法,只能用于求长度不能求序列。

 

#include <iostream>
#include <algorithm>
using namespace std;
const int N=50050;
int s[N],x;
int main()
{
    int n;
    while(cin>>n){
        int top=0;
        for(int i=0;i<n;i++){
            cin>>x;
            if(top==0||s[top-1]<x) s[top++]=x;
            else s[upper_bound(s,s+top,x)-s]=x;
        }
        cout<<top<<endl;
    }
    return 0;
}

 

 

 

 

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
  • 2021-12-25
  • 2022-02-02
  • 2022-12-23
猜你喜欢
  • 2022-01-13
  • 2021-10-01
  • 2021-07-04
  • 2022-02-13
  • 2021-11-17
相关资源
相似解决方案