Suffix array of the board a bit of a problem _ (: З"∠) _
1#include <Set>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <cstring>6#include <iostream>7#include <algorithm>8 #defineMAXN 300109 #defineMAXM 200010Ten using namespacestd; One intn =0, m, cnt =0, fen =10010; A intT[MAXM], T2[MAXM], SA[MAXM], C[MAXM], QWQ[MAXM], CH[MAXM], S[MAXM], BEL[MAXM], VIS[MAXN]; - intQ[MAXM], SUM[MAXN], Q[MAXM]; - voidGet_sa () { the intm = fen+1; - intI, *x = t, *y =T2; - for(i =0; I < m; i++) C[i] =0; - for(i =0; I < n; i++) C[x[i] = S[i]] + +; + for(i =1; I < m; i++) C[i] + = c[i-1]; - for(i = n1; I >=0; i--) Sa[--c[x[i]] =i; + for(intK =1; K <= N; K <<=1){ A intp =0; at for(i = n-k; i < n; i++) y[p++] =i; - for(i =0; I < n; i++)if(Sa[i] >= k) y[p++] = Sa[i]-K; - for(i =0; I < m; i++) C[i] =0; - for(i =0; I < n; i++) c[x[y[i]]]++; - for(i =0; I < m; i++) C[i] + = c[i-1]; - for(i = n1; I >=0; i--) sa[--c[x[y[i] []] =Y[i]; in swap (x, y); -p =1; x[sa[0]] =0; to for(i =0; I < n; i++) +X[sa[i]] = y[sa[i-1]]==y[sa[i]] && y[sa[i-1]+K]==Y[SA[I]+K]? P1: p++; -m =p; the } * } $ Panax Notoginseng voidread_s (inta) { - intl; thescanf"%d", &l); + for(inti =1; I <= l; i++) { ABel[n] = A, scanf ("%d", &s[n++]); the } +s[n++] = + +Fen; - } $ $ intJudgeint*p,intPosintLen) { - intSt =Sa[pos]; - for(inti =0; i < Len; i++) { the if(P[i] < s[i+st])return 1; - if(P[i] > S[i+st])return-1;Wuyi } the return 0; - } Wu - intMatchint*p,intlen) About { $ intL =-1, R = N, Mid, st =-1, t =0, en =0; - while(L +1<R) { -Mid = (l+r)/2; - intRET =judge (P, Mid, Len); A if(Ret >0) R =mid; + ElseL =mid; the } -En =l; $L =-1, r =N; the while(L +1<R) { theMid = (l+r)/2; the intRET =judge (P, Mid, Len); the if(Ret >=0) R =mid; - ElseL =mid; in } theSt =R; the inttot =0; About for(inti = st; I <= en; i++) { theQ[++T] =Bel[sa[i]]; the } the for(inti =1; I <= t; i++) { + if(!vis[q[i]]) vis[q[i]] =1, tot++, sum[q[i]]++; - } the for(inti =1; I <= t; i++) {Vis[q[i]] =0; }Bayi returntot; the } the - intSolve () { - intLen; thescanf"%d", &len); the for(inti =0; i < Len; i++) scanf ("%d", &ch[i]); the returnMatch (CH, len); the } - the voidRead_data () { the intA, B; thescanf"%d%d", &a, &b);94 for(inti =1; I <= A; i++) read_s (i), read_s (i); the Get_sa (); the for(inti =1; I <= b; i++) printf ("%d\n", Solve ()); the for(inti =1; I <= A; i++) {98 if(i! = a) printf ("%d", Sum[i]); About Elseprintf"%d", Sum[i]); - }101 }102 103 intMain () {104 Read_data (); the return 0;106}
BZOJ2754 Scoi2012day1t2 's name on the Meow planet (suffix array)