Test instructions: give you a string that asks for the coordinates of the oldest string and its starting position at least m times in the mid-term.
Idea: hash+lcp+ Two-point answer
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 6 Const intMAXN =40000+Ten;7 Const intx =123;8 intN, M, POS;9UnsignedLong LongH[MAXN], XP[MAXN];Ten OneUnsignedLong LongHASH[MAXN]; A intRANK[MAXN]; - - intcmpConst int& A,Const int&b) the { - returnHash[a] < Hash[b] | | (Hash[a] = = Hash[b] && a <b); - } - + intPossibleintL) - { + intc =0; Apos =-1; at for(inti =0; I < n-l+1; i++) - { -Rank[i] =i; -Hash[i] = h[i]-h[i+l]*Xp[l]; - } -Sort (rank, rank+n-l+1, CMP); in for(inti =0; I < n-l+1; i++) - { to if(i = =0|| Hash[rank[i]]! = hash[rank[i-1]]) +c =0; - if(++c >=m) thepos =Max (POS, rank[i]); * } $ returnPOS >=0;Panax Notoginseng } - the intMain () + { A CharS[MAXN]; the while(SCANF ("%d", &m) = =1&&m) + { -scanf"%s", s); $n =strlen (s); $H[n] =0; - for(inti = n1; I >=0; i--) -H[i] = h[i+1]*x + (S[i]-'a'); thexp[0] =1; - for(inti =1; I <= N; i++)WuyiXp[i] = xp[i-1]*x; the if(!possible (1)) -printf"none\n"); Wu Else - { About intL =1, R = n+1; $ while(R-l >1) - { - intM = L + (r-l)/2; - if(Possible (M)) AL =M; + ElseR =M; the } - Possible (L); $printf"%d%d\n", L, POS); the } the } the return 0; the}
View Code
Uvalive 4513 stammering Aliens