Tree-like array to solve LIS---O (nlogn)

Source: Internet
Author: User

Tree-like array to solve LIS---O (nlogn)
The LIS, which was previously written in two-point search, does not remember much now, just using bit to make a wave.
F[i] Indicates the length of the LIS ending with A[i].
T[X] Indicates the length of the LIS ending with a number x. That is T[x]=max (F[j]), A[j]==x,j<i.
F[i]=max (T[x]) +1,x<a[i] or x<=a[i] (depending on whether it rises or falls).
Most of them need to be discretized and then operated offline.

#include <iostream>#include<cstdio>#include<queue>#include<algorithm>#include<cmath>#include<ctime>#include<cstring>#defineINF 2147483647#definefor (I,A,B) for (register int i=a;i<=b;i++)#defineP (a) Putchar (a)#defineG () GetChar ()//by War//2017.10.17using namespacestd;intN;intt[100000];intans;intf[100000];intx;void inch(int&x) {    inty=1; CharC=g (); x=0;  while(c<'0'|| C>'9')    {    if(c=='-') y=-1; C=g (); }     while(c<='9'&&c>='0') x=x*Ten+c-'0', c=g (); X*=y;}voidOintx) {    if(x<0) {p ('-'); X=-x; }    if(x>9) O (x/Ten); P (x%Ten+'0');}intGetmax (intk) {    intmax=-inf;  for(;k>0; k-= (-K) &k) Max=Max (max,t[k]); returnMax;}voidModifyintKintMax) {     for(; k<=10000; k+= (-K) &k) T[k]=Max (T[k],max);}intMain () {inch(n); For (I,1, N) {        inch(x); F[i]=getmax (x) +1; Ans=Max (ans,f[i]);    Modify (X,f[i]);     } o (ANS); return 0;}
View Code

Tree-like array to solve LIS---O (nlogn)

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.