Surface
The pros and cons do a hash to judge, and then in two hashes to take a $max/min$ hash, and then each string of hash into the $set$, the final statistical set size, you can excellent in $o (nlog^2$ $n) $ in the solution
Then I think this is too no ideal, wrote a chain hash table, the result of running thieves slow ...
I hang the chain when the method is to change the modulus and then mold a new value, and then do this when the attention to the hash table and the cardinality and modulus of the partition
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 Const intn=200050, m=2500;6 Const Long Longbs=1009, md=2333;7 Const Long Longbas=203339, mod=2147483647;8 Long Longnum[n],hah[n][2],huh[n][2],pw[n][2],val[n];9 intP[m],nxt[n],outp[n];Ten intN,pos,cnt,ans; One Long LongGHash (intLintRintt) A { - Long LongMdd=t?MOD:MD; - Long LongH1= ((hah[r][t]-hah[l-1][t]*pw[r-l+1][t])%MDD+MDD)%MDD; the Long LongH2= ((huh[l][t]-huh[r+1][t]*pw[r-l+1][t])%MDD+MDD)%MDD; - returnMax (H1,H2); - } - BOOLFhash (Long LongHas,Long LongHSH) + { - for(intI=p[has%md];i;i=Nxt[i]) + if(VAL[I]==HSH)return true; A return false; at } - voidIhash (Long LongHas,Long LongHSH) - { - if(Fhash (HAS,HSH))return ; -nxt[++cnt]=p[pos=has%MD]; -val[cnt]=hsh,p[pos]=CNT; in } - intMain () to { +scanf"%d", &n), pw[0][0]=pw[0][1]=1; - for(intI=1; i<=n;i++) the { *scanf"%lld",&num[i]); $pw[i][0]=pw[i-1][0]*bs%MD;Panax Notoginsengpw[i][1]=pw[i-1][1]*bas%MoD; - } the for(intI=1; i<=n;i++) + { Ahah[i][0]= (hah[i-1][0]*bs+num[i])%MD; thehah[i][1]= (hah[i-1][1]*bas+num[i])%MoD; + } - for(inti=n;i;i--) $ { $huh[i][0]= (huh[i+1][0]*bs+num[i])%MD; -huh[i][1]= (huh[i+1][1]*bas+num[i])%MoD; - } the for(intI=1; i<=n;i++) - {WuyiMemset (P,0,sizeofp); Cnt=0; the for(intj=1; j<=n-i+1; j+=i) -Ihash (GHash (j,j+i-1,0), GHash (j,j+i-1,1)); Wu if(Cnt>ans) ans=cnt,outp[outp[0]=1]=i; - Else if(Cnt==ans) outp[++outp[0]]=i; About } $printf"%d%d\n", ans,outp[0]); - for(intI=1; i<=outp[0];i++) -printf"%d", Outp[i]); - return 0; A}
View Code
Problem solving: POI beads