Main topic:
For a given string, find all of its different substrings in the row K small substring
Build the suffix automaton first, and then we can view the entire suffix automaton as a dag graph, then we'll sort the topology to get *b[n]
A SC value is recorded for each node, indicating that the current node goes down to get the number of different strings
Then from the forward, each time to reach a node, the current node SC 1, and then each can go down the son node, the son of the SC added to the current node can be
Next get a ranking, starting from Root, from the A~z loop, right through SC to find the next incoming node
1#include <cstdio>2#include <iostream>3#include <cstring>4 5 using namespacestd;6 #defineN 900057 8 structsamnode{9 intL, SC;TenSamnode *son[ -] , *F; One}sam[n<<1], *root, *last, *b[n<<1]; A - intCNT, Num[n], N, K; - CharS[n]; the voidAddintx) - { -Samnode *p = &sam[++cnt], *JP =Last ; -P->l = jp->l+1; +Last =p; - for(; jp&&!jp->son[x]; jp=jp->f) jp->son[x] =p; + if(!JP) P->f =Root; A Else{ at if(jp->l+1= = jp->son[x]->l) P->f = jp->Son[x]; - Else{ -Samnode *r = &sam[++cnt], *q = jp->Son[x]; -*r = *q; R->l = jp->l+1; -P->f = Q->f =R; - for(; jp&&jp->son[x]==q; jp=jp->f) jp->son[x] =R; in } - } to } + - voidbuild () the { * intLen =strlen (s); $ for(intI=0; I<len; i++) Add (s[i]-'a');Panax Notoginseng for(intI=0; i<=cnt; i++) num[sam[i].l]++; - for(intI=1; I<=len; i++) num[i]+=num[i-1]; the for(intI=0; i<=cnt; i++) B[--NUM[SAM[I].L] = &Sam[i]; + A for(inti=cnt; i>=1; i--){ theB[i]->sc=1; + for(intj=0; j< -; J + +){ - if(b[i]->Son[j]) $B[i]->sc+=b[i]->son[j]->SC; $ } - } - } the - voidSolve ()Wuyi { thescanf"%d", &n); - CharTmp[n]; Wu intVal, t;//T represents the number of bits in TMP - while(n--){ Aboutscanf"%d", &k); $Samnode *cur =Root; -val =0, t=0; - while(val<k) { - for(intI=0; i< -; i++){ A if(cur->Son[i]) { + if(val+cur->son[i]->sc<k) val+=cur->son[i]->SC; the Else{ -val++; $tmp[t++] = i+'a'; theCur = cur->Son[i]; the Break; the } the } - } in } thetmp[t]=' /'; theprintf"%s\n", TMP); About } the } the the intMain () + { - //freopen ("a.in", "R", stdin); thescanf"%s", s);Bayiroot = last = &sam[cnt=0]; the build (); the solve (); - return 0; -}
Spoj Sublex K Boy string