Codeforces 486E LIS of Sequence

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.