Exercises
First determine if Len is the l-r of the circular section can be done O (1)
Just determine whether l-l+len-1 and R-len+1-r are the same, this step can be hashed
Then the circular section must be an approximate total length.
This can be done n√n, but will be t.
A ghost animal optimization is enumerated in each block within each letter number, this number must be the total number of approximate, then we take the GCD, and then enumerate the approximate.
Measurement can be done.
Another way to poke here: http://blog.csdn.net/zeyu_king/article/details/41989279
Code:
1#include <cstdio>2#include <cstdlib>3#include <cmath>4#include <cstring>5#include <algorithm>6#include <iostream>7#include <vector>8#include <map>9#include <Set>Ten#include <queue> One#include <string> A #defineINF 1000000000 - #defineMAXN 600000 - #defineMAXM 500+100 the #defineEPS 1e-10 - #defineull unsigned long Long - #definePA pair<int,int> - #defineFor0 (i,n) for (int i=0;i<= (n); i++) + #defineFor1 (i,n) for (int i=1;i<= (n); i++) - #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) A #defineMoD 1000000007 at using namespacestd; -InlineintRead () - { - intx=0, f=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} in returnx*F; - } to intn,m,a[maxn],c[maxn],s[maxn][ -]; + ull B[MAXN],POWER[MAXN]; - ConstUllBase=13131; theInline ullGet(intXintY) {returnb[x]-b[x+y]*power[y];} *InlineintgcdintXintY) {returnY?GCD (y,x%y): x;} $InlineintSolve ()Panax Notoginseng { - intX=read (), Y=read (), z=y-x+1, len=y-x+1, t=0; theFor1 (I, -) Z=GCD (z,s[y][i]-s[x-1][i]); + if(z==1)returnLen; A for(intI=1; i*i<=z;i++)if(z%i==0) the { + inttmp=len/z*i; - if(Get(x,len-tmp) = =Get(Y (len-tmp) +1, len-tmp))returntmp; $c[++t]=len/i; $ } -For3 (I,t,1)if(Get(X,len-c[i]) = =Get(Y (Len-c[i]) +1, Len-c[i]))returnC[i]; - returnLen; the } - intMain ()Wuyi { theFreopen ("Input.txt","R", stdin); -Freopen ("output.txt","W", stdout); WuN=read (); n=0; - CharCh=GetChar (); About while(ch<'a'|| Ch>'Z') ch=GetChar (); $ for(; ch>='a'&&ch<='Z'; Ch=getchar ()) a[++n]=ch-'a'+1; -For3 (I,n,1) b[i]=b[i+1]*Base+A[i]; -For1 (I,n) For1 (J, -) s[i][j]=s[i-1][j]+ (a[i]==j); -power[0]=1; AFor1 (i,n) power[i]=power[i-1]*Base; +m=read (); the while(m--) printf ("%d\n", Solve ()); - return 0; $}
View Code 2795: [Poi2012]a horrible Poem time limit:50 Sec Memory limit:128 MB
submit:121 solved:72
[Submit] [Status] Description
A string s consisting of lowercase English letters is given, and Q is asked to answer the shortest follow-up link of a substring of s.
If string B is a looping section of string A, then a can be repeated several times by B.
Input
The first line is a positive integer n (n<=500,000), which represents the length of S.
The second row of n lowercase English letters, representing the string s.
The third line is a positive integer q (q<=2,000,000), which indicates the number of queries.
The following q lines are two positive integers a, B (1<=a<=b<=n), representing the query string s[a: b] The shortest cycle section length.
Output
Output Q-line positive integers, and the positive integers of line I correspond to the answer of the I query.
Sample Input8
Aaabcabc
3
1 3
3 8
4 8
Sample Output1
3
5HINT Source
Acknowledgement Jiangzoi&oimaster
BZOJ2795: [Poi2012]a horrible Poem