本地跑没有问题,但是测评O2变成RE,不加O2TLE
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;
const ll MAXN=1e6+50000;
const ull base=233;
char s[MAXN];
ull hsh[MAXN],mi[MAXN];
ull geth(int l,int r){return hsh[r]-hsh[l-1]*mi[r-l+1];}
ll pre[MAXN][35],ed[MAXN],cnt[250], num = 0;
int main()
{
// freopen("string.in","r",stdin);
// freopen("string.out","w",stdout);
ll T,len;
scanf("%lld",&T);
while(T--){
scanf("%s",s+1);
len=strlen(s+1);
hsh[0] = 0, mi[0] = 1;
for(int i=1;i<=len;i++){
hsh[i] = hsh[i-1]*base+s[i];
mi[i]=mi[i-1]*base;
}
memset(cnt,0,sizeof(cnt));
memset(pre,0,sizeof(pre));
num = 0;
for(int i=1;i<=len;i++){
if(cnt[s[i]-'a']&1) num--;
else num++;
for(int j = 0; j <= 26; j++) pre[i][j] = pre[i-1][j]+(num<=j);
cnt[s[i]-'a']++;
}
memset(cnt,0,sizeof(cnt));
ed[len+1]=0;
for(int i=len;i>=1;i--){
ed[i]=ed[i+1];
if(cnt[s[i]-'a']&1) ed[i]--;
else ed[i]++;
cnt[s[i]-'a']++;
}
ll ans=0;
for(int x=2;x<len;x++){
ull num=geth(1,x);
for(ll st = 0; st < len; st += x){
if(geth(st+1,st+x) != num || st+x>=len) break;
ans += pre[x-1][ed[st+x+1]];
}
}
printf("%lld\n",ans);
}
return 0;
}
/*
1
mmlmmlo
*/