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)