Description
To an array of A1, A2 ... an, find the longest ascending descending subsequence ab1<ab2<. <ABK, of which b1<b2< Bk.
The output length can be.
Input
The first line, an integer n.
Second row, n integers (n < = 1000000)
Output
Maximum value of the output K, which is the length of the longest non-descending sub-sequence
Sample Input
5
9 3 6) 2 7
Sample Output
3
HINT
n<=1000000
To facilitate debugging, the data name has been modified--three
/*maintain ascending sequence c[] for a[i], if it is larger than the last element of the C sequence, insert it directly otherwise binary find a[i] position in C, if C[J]<A[I]<C[J+1], then the length of the overlay sequence C for c[j+1] is the answer */#include<iostream>#include<cstdio>using namespacestd;inta[1000010];intc[1000010];intMain () {intN scanf"%d",&N); for(intI=1; i<=n;i++) scanf ("%d",&A[i]); c[1]=a[1]; intCnt=1; for(intI=2; i<=n;i++) { if(a[i]>c[cnt]) c[++cnt]=A[i]; Else{ intL=1, r=Cnt,mid; while(l<R) {Mid= (l+r)/2; if(C[mid]>=a[i]) r=mid; if(c[Mid]<a[i]) l=mid+1; } if(A[i]<c[l]) c[l]=A[i]; }} cout<<CNT;}
"CODEVS3995" the Longest Strictly ascending subsequence (enhanced version)