AcWing 896. 最长上升子序列 II
原题链接
中等
作者:
Franks
,
2019-12-25 18:59:07
,
所有人可见
,
阅读 820
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 100010;
typedef long long ll;
ll a[N];
int q[N]; // q[i] 表示以i为递增数列的最后一个元素的值的序列q[0..i]
int n;
int main(){
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%lld", &a[i]);
q[0] = a[0];
int k = 0;
for(int i = 1; i < n; i++){
if(a[i] > q[k]) q[++k] = a[i];
else{
int l = 0, r = k;
while(l < r){
int mid = l + r >> 1;
if(q[mid] < a[i]) l = mid + 1;
else r = mid;
}
q[l] = a[i];
}
}
printf("%d", k+1);
return 0;
}