Topic: Given a number string, all k satisfies when dividing the number of numbers from left to right into blocks of size K, the number of different blocks is the most inverse isomorphism.
Enumeration k, for each k insert a different string into the hash table to go heavy
Reverse the hash of each string that is isomorphic and multiply the hash value of the crossdress.
Time complexity O (n/1+n/2+...+n/n) =o (NLOGN)
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 200200# Define BASE 200191#define MOD 999911657using namespace Std;int n,ans,a[m];long long Hash1[m],hash2[m],power[m];int stack [M],top;namespace hash_table{struct list{int hash_value;bool flag; List *next; List (int _,list *__): Hash_value (_), flag (false), next (__) {}}*head[base];int tim[base],t;void Initialize () {++t;} bool& hash (int hash) {int pos=hash%base;if (tim[pos]!=t) tim[pos]=t,head[pos]=0x0;for (List *temp=head[pos];temp; Temp=temp->next) if (Temp->hash_value==hash) return Temp->flag;return (Head[pos]=new List (Hash,head[pos]))- >flag;}} int main () {using namespace Hash_table;int i,j;cin>>n;for (i=1;i<=n;i++) scanf ("%d", &a[i]); for (i=1;i< =n;i++) hash1[i]= (Hash1[i-1]*base+a[i])%mod;for (i=n;i;i--) hash2[i]= (Hash2[i+1]*base+a[i])%MOD;for (power[0]=1,i= 1;i<=n;i++) power[i]=power[i-1]*base%mod;for (i=1;i<=n;i++) {int cnt=0;initialize (); for (j=i;j<=n;j+=i) { int l=j-I+1,r=j;long long _hash1= (hash1[r]-hash1[l-1]*power[r-l+1]%mod+mod)%mod;long long _hash2= (hash2[l]-hash2[r+1]* Power[r-l+1]%mod+mod)%mod;bool &flag=hash (_hash1*_hash2%mod), if (!flag) ++cnt;flag=1;} if (Cnt>ans) ans=cnt,top=0;if (Cnt==ans) stack[++top]=i;} cout<<ans<< ' <<top<<endl;for (i=1;i<=top;i++) printf ("%d%c", stack[i], "\ n" [I==top]); return 0;}
Bzoj 2801 Poi2010 Beads Hash