CSU1656: Paper of FlyBrother (suffix array)
Description
FlyBrother is a superman, therefore he is always busy saving the world.
To graduate from NUDT is boring but necessary for him. typically We need to post an paper to get Graduate Certificate, however being one superman, FlyBrother wants to make his paper perfect. A paper is a lower case string. to make it perfect, FlyBrother wanna the number of different substrings in the paper. it is quite a silly problem for FlyBrother, but because he is so busy, can you help him to s Olve it?
Input
There are several cases. Process till EOF.
For each case, there is a line of lower case string (1 <= length <= 100000 ).
Output
For each case, output one number in a line of the answer described in the problem.
Sample Input
aaab
Sample Output
15
HINT
Evaluate the number of different strings
Idea: I have the same questions and template questions in my suffix array question summary.
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; # define LS 2 * I # define RS 2 * I + 1 # define UP (I, x, y) for (I = x; I <= y; I ++) # define DOWN (I, x, y) for (I = x; I> = y; I --) # define MEM (a, x) memset (, x, sizeof (a) # define W (a) while (a) # define gcd (a, B) _ gcd (a, B) # define LL long # define N 100005 # define MOD 1000000007 # define INF 0x3f3f3f # define EXP 1e-8www.bkjia.comLL wa [N], wb [N], wsf [N], wv [N], sa [N]; LL rank1 [N], height [N], s [N], a [N]; char str [N], str1 [N], str2 [N]; // sa: the starting position of the nth position in the Lexicographic Order in str sa [I] // rank: that is, the suffix of str I position is in the Lexicographic Order of the nth // height: the longest public prefix of the Lexicographic Order of I and the suffix of the I-1 LL cmp (LL * r, LL, LL B, LL k) {return r [a] = r [B] & r [a + k] = r [B + k];} void getsa (LL * r, LL * sa, LL n, LL m) // n should contain the 0 {LL I, j, p, * x = wa, * y = wb, * t; for (I = 0; I
= 0; I --) sa [-- wsf [x [I] = I; p = 1; j = 1; for (; p
= J) y [p ++] = sa [I]-j; for (I = 0; I
= 0; I --) sa [-- wsf [wv [I] = y [I]; t = x; x = y; y = t; x [sa [0] = 0; for (p = 1, I = 1; I