Title: http://www.lydsy.com/JudgeOnline/problem.php?id=1264
Because each character appears at most 5 times, it is recorded in a. Then sweep through B, because A[i]=b[j] is f[i]++, so maintaining a tree array record maximum is OK.
Note the order of transfers
#include <cstring>#include<iostream>#include<cstdio>#include<map>#include<cmath>#include<algorithm>#defineRep (i,l,r) for (int i=l;i<=r;i++)#defineDown (i,l,r) for (int i=l;i>=r;i--)#defineCLR (x, y) memset (x,y,sizeof (×))#defineLow (x) (x& (×))#defineMAXN 100500#defineINF 2000000000#defineMM 1000000007using namespacestd;inta[maxn][6],N,T[MAXN],CNT[MAXN],F[MAXN];intRead () {intx=0, f=1;CharCh=GetChar (); while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=GetChar ();} while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;}voidAddintXinty) { while(x<=N) {T[x]=Max (t[x],y); X+=Low (x); }}intAskintx) { intans=0; while(x>0) {ans=Max (ans,t[x]); X-=Low (x); } returnans;}intMain () {intans=0; N=read (); N=n*5; Rep (I,1, N) { intx=read (); a[x][++cnt[x]]=i; } Rep (I,1, N) { intx=read (); Down (J,5,1) { intnow=A[x][j]; F[now]=max (F[now],ask (now-1)+1); Add (Now,f[now]); Ans=Max (Ans,f[now]); }} printf ("%d\n", ans); return 0;}
BZOJ1264: [AHOI2006] gene matches match