Portal: http://www.lydsy.com/JudgeOnline/problem.php?id=1031
Save the suffix array template.
In fact, if the data range is smaller, or the space limit is a little larger, or even as long as the alphabet is a little bit more can use the suffix automaton, but unfortunately the space is not allowed, just use the suffix array!
In fact, I still do not understand the code, whether it should be a black box code back down?
#include <cstdio> #include <cstring> #include <algorithm>const int maxn = 200005;int N, mx, SA[MAXN], t1[ MAXN], T2[MAXN], C[MAXN], *x, *y;char s[maxn];int main (void) {scanf ("%s", s), n = strlen (s); memcpy (s + N, S, n-1); n = (n << 1)-1;x = T1;y = T2;mx = 128;memset (c, 0, sizeof c); for (int i = 0; i < n; ++i) {++c[x[i] = s[i];} for (int i = 1; i < mx; ++i) {C[i] + = c[i-1];} for (int i = n-1; ~i; i.) {sa[--c[x[i]]] = i;} int p;for (int k = 1; k <= N; k <<= 1) {p = 0;for (int i = n-k; i < n; ++i) {y[p++] = i;} for (int i = 0; i < n; ++i) {if (Sa[i] >= k) {y[p++] = sa[i]-k;}} memset (c, 0, sizeof c); for (int i = 0; i < n; ++i) {++c[x[y[i]];} for (int i = 0; i < mx; ++i) {C[i] + = c[i-1];} for (int i = n-1; ~i; i.) {SA[--C[X[Y[I]]] [= Y[i];} Std::swap (x, y);p = 1;x[sa[0]] = 0;for (int i = 1; i < n; ++i) {x[sa[i]] = y[sa[i-1] [= Y[sa[i]] && y[sa[i- 1] + K] = = Y[sa[i] + K]? P-1: p++;} if (P >= N) {break;} mx = p;} Int TEM = (n + 1) >> 1;for (int i = 0; i < n; ++i) {if (Sa[i] < tem) {printf ("%c", S[sa[i] + tem-1]);}} return 0;}
_bzoj1031 [JSOI2007] character encryption cipher "suffix array"