Surface
Hihocoder
Sol
The tip of the topic is very good.
I add to the request \ (LCP (p-l + Len \% L, P + len \% l) \)
\ (LEN=LCP (p, p + L) \)
Why only ask \ (LCP (p-l + Len \% L, P + len \% l) ?
Consider the right to \ ( p\) between \ (p-l + len \% l\) , which is no larger than the number of repetitions here
Consider the p-l + len \% l\ to the left to \ (p-1\) , the same as it does not increase
# include <bits/stdc++.h># define IL inline# define RG Register# define Fill (A, B) memset (A, B, sizeof (a))using namespaceStdtypedef Long LongllConst int_(100010);intN, A[_], sa[_], rk[_], y[_], height[_], t[_], vis[_];intst[ -][_], lg[_];CharS[_];ilBOOLCMP (RGintI, RGintJ, RGintK) {returnY[i] = = Y[j] && y[i + K] = = Y[j + K]; }ilvoidSort () {RGintm = -; for(RGinti =1; I <= N; ++i) ++t[rk[i] = A[i]; for(RGinti =1; I <= m; ++i) T[i] + = t[i-1]; for(RGinti = n; I -I.) sa[t[rk[i]]--] = i; for(RGintK =1; K <= N; K <<=1) {RGintL =0; for(RGinti = N-k +1; I <= N; ++i) Y[++l] = i; for(RGinti =1; I <= N; ++i)if(Sa[i] > k) y[++l] = sa[i]-K; for(RGinti =0; I <= m; ++i) T[i] =0; for(RGinti =1; I <= N; ++i) ++t[rk[y[i]]; for(RGinti =1; I <= m; ++i) T[i] + = t[i-1]; for(RGinti = n; I -i) sa[t[rk[y[i]]]--] = Y[i]; Swap (RK, y); rk[sa[1]] = L =1; for(RGinti =2; I <= N; ++i) Rk[sa[i] = CMP (Sa[i-1], Sa[i], K)? L: ++l;if(l >= N) Break; m = l; } for(RGinti =1, j =0; I <= N; ++i) {j = max (0, J-1); while(A[j + i] = = A[sa[rk[i]-1] + j]) ++j; Height[rk[i]] = j; }}ilintLCP (RGintXX, RGintYY) {xx = rk[xx]; yy = Rk[yy];if(xx > yy) swap (xx, yy); ++xx; RgintL = lg[yy-xx +1];returnMin (st[l][xx], St[l][yy-(1<< l) +1]);} ILintCalc () {RGintAns =0; for(RGintL =1; L <= N; ++L) for(RGinti =1; i + L <= N; i + = L) {RGintLen = LCP (i, i + L); ans = max (ans, len/l +1);if(I >= l-len% l) ans = max (ans, LCP (i-l + len% l, i + len% l)/L +1); }returnAns;}intMain (RGintARGC, RGChar* argv[]) {scanf (" %s", S +1); n = strlen (s +1); for(RGinti =1; I <= N; ++i) A[i] = s[i]-' A '+1; for(RGinti =2; I <= N; ++i) Lg[i] = Lg[i >>1] +1; Sort (); for(RGinti =1; I <= N; ++i) st[0][i] = Height[i]; for(RGinti =1; I <= Lg[n]; ++i) for(RGintj =1; J + (1<< i)-1<= N; ++J) St[i][j] = min (St[i-1][J], St[i-1][j + (1<< (I-1))]); printf"%d\n", Calc ());return 0;}
HiHocoder1419: suffix array four • Repeat Melody 4