The topic asks for the longest repetition K-th overlapping substrings.
and POJ1743.
- Two-minute enumeration of ANS determines whether it is established
- Height group, if the number of groups greater than or equal to ans is greater than or equal to k-1, this ans is feasible
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 #defineMAXN 10000016 7 intWA[MAXN],WB[MAXN],WV[MAXN],WS[MAXN];8 intcmpint*r,intAintBintl) {9 returnR[A]==R[B] && r[a+l]==r[b+l];Ten } One intSA[MAXN],RANK[MAXN],HEIGHT[MAXN]; A voidSA (int*r,intNintm) { - int*x=wa,*y=WB; - the for(intI=0; i<m; ++i) ws[i]=0; - for(intI=0; i<n; ++i) ++ws[x[i]=R[i]]; - for(intI=1; i<m; ++i) ws[i]+=ws[i-1]; - for(inti=n-1; i>=0; -I.) sa[--ws[x[i]]]=i; + - intp=1; + for(intj=1; p<n; j<<=1, m=p) { Ap=0; at for(intI=n-j; i<n; ++i) y[p++]=i; - for(intI=0; i<n; ++i)if(SA[I]>=J) y[p++]=sa[i]-J; - for(intI=0; i<n; ++i) wv[i]=X[y[i]]; - for(intI=0; i<m; ++i) ws[i]=0; - for(intI=0; i<n; ++i) + +Ws[wv[i]]; - for(intI=1; i<m; ++i) ws[i]+=ws[i-1]; in for(inti=n-1; i>=0; -I.) sa[--ws[wv[i]]]=Y[i]; -Swap (x, y); x[sa[0]]=0; p=1; to for(intI=1; i<n; ++i) x[sa[i]]=cmp (y,sa[i-1],sa[i],j)? p1:p + +; + } - the for(intI=1; i<n; ++i) rank[sa[i]]=i; * intk=0; $ for(intI=0; i<n-1; height[rank[i++]]=k) {Panax Notoginseng if(k)--K; - for(intj=sa[rank[i]-1]; R[I+K]==R[J+K]; ++k); the } + } A the intN,K,A[MAXN]; + BOOLisOKintLen) { - intCnt=0; $ BOOLflag=0; $ for(intI=2; i<=n; ++i) { - if(height[i]>=Len) { - if(flag) { the++CNT; - if(cnt+1>=K)return 1;Wuyi}Else{ theflag=1; -Cnt=1; Wu if(cnt+1>=K)return 1; - } About}Else{ $flag=0; -Cnt=0; - } - } A return 0; + } the intMain () { - intmx=0; $scanf"%d%d",&n,&k); the for(intI=0; i<n; ++i) { thescanf"%d", A +i); theMx=max (mx,++a[i]); the } -a[n]=0; inSA (a,n+1, mx+1); the intL=0, r=N; the while(l<R) { About intmid=l+r+1>>1; the if(isOK (mid)) l=mid; the Elser=mid-1; the } +printf"%d", L); - return 0; the}
POJ3261 Milk Patterns (binary + suffix array)