Main topic:
A sequence that asks whether each element is an element in all the longest ascending subsequence or a few, but not all, of the longest ascending subsequence, or one of the longest ascending sub-sequences.
Ideas:
The length of the longest ascending subsequence with each element as the beginning and end, if the sum of the two is smaller than the longest ascending subsequence length of +1, then neither is one; otherwise, if another element is exactly the same as its two value, it is not all;
Code:
1#include <map>2#include <cstdio>3#include <algorithm>4 using namespacestd;5 Const intm=100009;6Map <pair<int,int,int>MP;7 intI,n,top,a[m],st[m],f1[m],f2[m];8 BOOLFlag[m];9 Ten voidLIS (int*f) One { Ast[top=1]=a[1]; f[1]=1; - for(intI=2; i<=n;++i) - if(St[top]<a[i]) st[++top]=a[i],f[i]=top; the Else - { - intL=1, r=top,ans=0; - while(l<=R) + { - intMid=l+r>>1; + if(St[mid]<a[i]) ans=mid,l=mid+1;Elser=mid-1; A } atst[ans+1]=A[i]; -f[i]=ans+1; - } - } - - intMain () in { -scanf"%d",&n); to for(i=1; i<=n;++i) scanf ("%d",&a[i]); + LIS (F1); - for(i=1; i<=n;++i) a[i]=m-A[i]; the for(i=1; i+i<=n;++i) Swap (a[i],a[n+1-i]); * LIS (F2); $ for(i=1; i+i<=n;++i) Swap (f2[i],f2[n+1-i]);Panax Notoginseng++top; - for(i=1; i<=n;++i) the if(f1[i]+f2[i]==top) + +Mp[make_pair (F1[i],f2[i]); + Elseflag[i]=1; A for(i=1; i<=n;++i) the if(!Flag[i]) + if(Mp[make_pair (F1[i],f2[i])]==1) printf ("3"); - Elseprintf"2"); $ Elseprintf"1"); $ return 0; -}
Codeforces 486E LIS of Sequence