An array of suffixes. Cannot overlap the longest repeating substring.
Two-point answer + validation. Each time, the suffix of the sorted sequence is grouped in order. The longest common prefix of any two in each group is to >= two points. If there is a set of two suffixes in the SA value difference is greater than or equal to two points, then this two-score is feasible.
#pragmaComment (linker, "/stack:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<Set>#include<queue>#include<stack>#include<iostream>using namespaceStd;typedefLong LongLL;Const DoublePi=acos (-1.0), eps=1e-8;voidFile () {freopen ("D:\\in.txt","R", stdin); Freopen ("D:\\out.txt","W", stdout);} InlineintRead () {Charc = GetChar (); while(!isdigit (c)) C =GetChar (); intx =0; while(IsDigit (c)) {x = x *Ten+ C-'0'; c =GetChar ();} returnx;}Const intmaxn=20000+Ten;intWA[MAXN],WB[MAXN],WV[MAXN],WS[MAXN];intcmpint*r,intAintBintl) { returnr[a]==r[b]&&r[a+l]==r[b+l];}voidDaint*r,int*sa,intNintm) { inti,j,p,*x=wa,*y=wb,*T; for(i=0; i<m; i++) ws[i]=0; for(i=0; i<n; i++) ws[x[i]=r[i]]++; for(i=1; i<m; i++) ws[i]+=ws[i-1]; for(i=n-1; i>=0; i--) sa[--ws[x[i]]]=i; for(j=1, p=1; p<n; j*=2, m=p) { for(p=0, I=n-j; i<n; i++) y[p++]=i; for(i=0; i<n; i++)if(SA[I]>=J) y[p++]=sa[i]-J; for(i=0; i<n; i++) wv[i]=X[y[i]]; for(i=0; i<m; i++) ws[i]=0; for(i=0; i<n; i++) ws[wv[i]]++; for(i=1; i<m; i++) ws[i]+=ws[i-1]; for(i=n-1; i>=0; i--) sa[--ws[wv[i]]]=Y[i]; for(t=x,x=y,y=t,p=1, x[sa[0]]=0, i=1; i<n; i++) X[sa[i]]=CMP (y,sa[i-1],sa[i],j)? p1:p + +; } return;}intRANK[MAXN],HEIGHT[MAXN];voidCalheight (int*r,int*sa,intN) { inti,j,k=0; for(i=1; i<=n; i++) rank[sa[i]]=i; for(i=0; i<n; height[rank[i++]]=k) for(k?k--:0, j=sa[rank[i]-1]; R[I+K]==R[J+K]; k++); return;}intN,A[MAXN],SA[MAXN];BOOLCheckintx) { intmin=sa[0],max=sa[0]; height[n+1]=0; for(intI=1; i<=n+1; i++) { if(height[i]>=x) {min=min (Min,sa[i]), Max=max (Max,sa[i]);Continue; } if(max-min>=x)return 1; Min=sa[i]; max=Sa[i]; } return 0;}intMain () { while(~SCANF ("%d",&N)) {if(n==0) Break; for(intI=0; i<n;i++) scanf ("%d", &a[i]); n--; for(intI=0; i<n;i++) a[i]=a[i+1]-a[i]+ -; A[n]=0; Da (a,sa,n+1, $); Calheight (A,sa,n); intL=4, r=n+1, ans=0; while(l<=R) {intMid= (L+R)/2; if(Check (mid)) ans=mid,l=mid+1; Elser=mid-1; } ans++;if(ans<=4) ans=0; printf ("%d\n", ans); } return 0;}
POJ 1743 Musical Theme