POJ 2774 suffix array: Find the longest common substring
Idea: in fact, it is very simple, that is, two strings are connected, separated by a special character in the middle, and then the longest public prefix is obtained using the suffix array, and then different in the two strings, and the longest is the longest public substring.
Note: The first string is used to determine whether it is in the same character. At first, the length of the second character is used to determine whether it is found after WA 2 is sent.
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Define mem (a, B) memset (a, B, sizeof (a) # define lson I <1, l, mid # define rson I <1 | 1, mid + 1, r # define llson j <1, l, mid # define rrson j <1 | 1, mid + 1, r # define INF 0x7fffffff # define maxn 200010 using namespace std; typedef long ll; typedef unsigned long ull; void radix (int * str, int * a, int * B, int n, int m) {static int count [maxn]; mem (count, 0); for (int I = 0; I
= 0; I --) B [-- count [str [a [I] = a [I];} void suffix (int * str, int * sa, int n, int m) // calculate the suffix array sa {static int rank [maxn], a [maxn], B [maxn]; for (int I = 0; I
= N? 0: rank [j + (1 <
> S> ss) {ss = s + "#" + ss; copy (ss. begin (), ss. end (), a); int n = ss. size (), len = 0; suffix (a, sa, n, 256); calcHeight (a, sa, height, rank, n); for (int I = 1; I
Len & (sa [I]