Topic: Given a string, the starting position of the loop string, you can get a different string length, ask to sort these strings after the first bit of each string is what.
Idea: The suffix array is bare, just multiply the entire string and then ask the SA.
CODE:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 200010using namespace Std;char s[max];int len;int sa[max],val[max];inline bool Same (int x,int y,int l,int len) {return val[ X] = = Val[y] && ((x + l >= len && y + l >= len) | | (x + L < len && y + L < len && val[x + l] = = Val[y + l]));} void Getsaffixarray () {static int cnt[max],_val[max],q[max],lim = 256,j;for (int i = 0; i < Lim; ++i) cnt[i] = 0;for (int i = 0; i < Len; ++i) ++cnt[val[i] = s[i]];for (int i = 1; i < Lim; ++i) cnt[i] + = cnt[i-1];for (int i = len-1; I >= 0; i.) sa[--cnt[ Val[i]] = i;for (int d = 1;; ++d) {int top = 0,l = 1 << (d-1); for (int i = 0; i < len; ++i) if (Sa[i] + L >= le N) q[top++] = sa[i];for (int i = 0; i < len; ++i) if (Sa[i] >= l) q[top++] = Sa[i]-l;for (int i = 0; i < Lim; ++i) CNT [I] = 0;for (int i = 0; i < len; ++i) ++cnt[val[q[i]]];for (int i = 1; i < Lim; ++i) cnt[i] + = Cnt[i-1];for (int i = len-1; I >= 0; i.) sa[--cnt[val[q[i]]] = Q[i];lim = 0;for (int i = 0; i < len; ++lim) {for (j = i; J < ; Len-1 && Same (sa[j],sa[j + 1],l,len); ++J); for (; I <= J; ++i) _val[sa[i]] = lim;} for (int i = 0; i < len; ++i) Val[i] = _val[i];if (lim = = len) break; return;} int main () {scanf ("%s", s), Len = strlen (s), for (int i = len; i < len << 1; ++i) s[i] = S[i-len];s[len << 1] = ' n '; len = strlen (s); Getsaffixarray (); for (int i = 0; i < len; ++i) if (Sa[i] < (len >> 1) putchar (S[sa[i] + (len >> 1)-1]); re Turn 0;}
Bzoj 1031 Jsoi 2007-character encryption cipher suffix array