```cpp
#include<cstdio>
#include<cstring>
#define rg register
#define ll long long
const int ntf=377487361,NtF=469762049,NTF=998244353;
char c;
ll ans;
int t,n;
int apr[37];
int a[1100003];
int prev[1100003];
int posv[1100003];
int pret[110003];
ll pwr[7][1100003];
ll hsh[7][1100003];
int pres[37][1100003];
inline bool chk(int x,int y)
{
if((hsh[0][x]+pwr[0][x]*hsh[0][y-x]%ntf)%ntf!=hsh[0][y])return false;
if((hsh[1][x]+pwr[1][x]*hsh[1][y-x]%NtF)%NtF!=hsh[1][y])return false;
if((hsh[2][x]+pwr[2][x]*hsh[2][y-x]%NTF)%NTF!=hsh[2][y])return false;
return true;
}
void print(ll x)
{
if(x>9)print(x/10);
putchar(x%10+'0');
}
int main()
{
scanf(" %d",&t);
c=getchar();
hsh[0][0]=hsh[1][0]=hsh[2][0]=0;
pwr[0][0]=pwr[1][0]=pwr[2][0]=1;
while(t--)
{
ans=n=0;
while(c<'a'||c>'z')c=getchar();
while(c>='a'&&c<='z')a[++n]=c-'a',c=getchar();
for(rg int i=1;i<=n+1;++i)
{
hsh[0][i]=(hsh[0][i-1]*26+a[i])%ntf;
hsh[1][i]=(hsh[1][i-1]*26+a[i])%NtF;
hsh[2][i]=(hsh[2][i-1]*26+a[i])%NTF;
pwr[0][i]=pwr[0][i-1]*26%ntf;
pwr[1][i]=pwr[1][i-1]*26%NtF;
pwr[2][i]=pwr[2][i-1]*26%NTF;
}
for(rg int i=0;i<26;++i)apr[i]=0;
for(rg int i=1;i<=n;++i)
{
apr[a[i]]^=1;prev[i]=0;
for(rg int j=0;j<26;++j)if(apr[j])++prev[i];
for(rg int j=0;j<26;++j)pres[j][i+1]=pres[j][i]+(prev[i]<=j);
}
for(rg int i=0;i<26;++i)apr[i]=0;
for(rg int i=n;i;--i)
{
apr[a[i]]^=1;posv[i]=0;
for(rg int j=0;j<26;++j)if(apr[j])++posv[i];
}
for(rg int i=2;i<n;++i)
{
rg int l=1,r=(n-1)/i,m;
while(l<r)
{
m=r-((r-l)>>1);
if(chk((m-1)*i,m*i))l=m;
else r=m-1;
}
pret[i]=l;
}
for(rg int i=2;i<n;++i)
{
for(rg int j=1;j<=pret[i];++j)
{
ans+=pres[posv[i*j+1]][i];
}
}
print(ans);putchar('\n');
}
return 0;
}
```
by VinstaG173 @ 2020-12-18 21:35:10
别用三hash,单hash好写一些。三个hash,别人都不方便帮你debug了(友善的建议)
by 天命之路 @ 2020-12-18 21:58:31
@[Remus_John_Lupin](/user/59388) 话说是不是不能用 0-25 这个范围啊(好像全是 a 就会有问题)
by tiger2005 @ 2020-12-18 22:08:03
@[tiger2005](/user/60864) 哦懂了,wssb(
by VinstaG173 @ 2020-12-18 22:09:18
@[tiger2005](/user/60864) 还是不行(
by VinstaG173 @ 2020-12-18 22:13:23