1 #include <iostream> 2 #include <algorithm> 3 #include <stdio.h> 4 #define MAXN 50010 5 using namespace std; 6 7 const int MIN = -1e9; 8 9 int main(void){ 10 int n, a[MAXN], vis[MAXN], len = 1; 11 scanf("%d", &n); 12 for (int i = 0; i<n; i++){ 13 scanf("%d", &a[i]); 14 } 15 for (int i = 0; i <= n; i++){ 16 vis[i] = MIN; 17 } 18 19 //vis[i]表示满足递增数量i的最小值 20 vis[1] = a[0]; 21 for (int i = 1; i<n; i++){ 22 //upper_bound(vis + 1, vis + len + 1, a[i]) 返回被查序列中第一个大于查找值的指针 23 int pos = upper_bound(vis + 1, vis + len + 1, a[i]) - vis; 24 vis[pos] = a[i]; 25 if (len<pos){ //维护最大长度 26 len = pos; 27 } 28 } 29 printf("%d\n", len); 30 return 0; 31 }