# 题意

1、位置和字符都关于某条对称轴对称。
2、不能是连续的一段。

# sol

$s[i]==s[2x-i]$

## code

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const double Pi = acos(-1);
const int mod = 1e9+7;
const int N = 4e5+5;
struct Complex{
double rl,im;
Complex(){rl=im=0;}
Complex(double a,double b){rl=a;im=b;}
Complex operator + (Complex b)
{return Complex(rl+b.rl,im+b.im);}
Complex operator - (Complex b)
{return Complex(rl-b.rl,im-b.im);}
Complex operator * (Complex b)
{return Complex(rl*b.rl-im*b.im,rl*b.im+im*b.rl);}
}w[N],a[N];
int n,m,l,rev[N],tw[N],f[N],p[N],mx,id,ans;
char s[N];
void FFT(Complex *P,int opt)
{
for (int i=0;i<n;++i) if (i>rev[i]) swap(P[i],P[rev[i]]);
for (int i=1;i<n;i<<=1)
for (int p=i<<1,j=0;j<n;j+=p)
for (int k=0;k<i;++k)
{
Complex W=w[n/i*k];W.im*=opt;
Complex X=P[j+k],Y=W*P[j+k+i];
P[j+k]=X+Y;P[j+k+i]=X-Y;
}
if (opt==-1) for (int i=0;i<n;++i) P[i].rl/=1.0*n;
}
void work(char ch)
{
for (int i=0;i<n;++i) a[i]=Complex(s[i]==ch,0);
FFT(a,1);
for (int i=0;i<n;++i) a[i]=a[i]*a[i];
FFT(a,-1);
for (int i=2;i<=(m<<1);++i) f[i]+=((int)(a[i].rl+0.5)+1)/2;
}
int main()
{
scanf("%s",s+1);m=strlen(s+1);
tw[0]=1;
for (int i=1;i<=m;++i) tw[i]=2ll*tw[i-1]%mod;
for (n=1;n<=(m<<1);n<<=1) ++l;--l;
for (int i=0;i<n;++i) rev[i]=(rev[i>>1]>>1)|((i&1)<<l);
for (int i=0;i<n;++i) w[i]=Complex(cos(Pi*i/n),sin(Pi*i/n));
work('a');work('b');
for (int i=2;i<=(m<<1);++i)
(ans+=tw[f[i]]-1)%=mod;
s[0]='%';s[m<<1|1]='#';
for (int i=m;i;--i)
s[2*i]=s[i],s[2*i-1]='#';
for (int i=1;i<=(m<<1);++i)
{
p[i]=mx>i?min(p[2*id-i],mx-i):1;
while (s[i-p[i]]==s[i+p[i]]) ++p[i];
if (i+p[i]>mx) mx=i+p[i],id=i;
}
for (int i=1;i<=(m<<1);++i)
ans=(ans-p[i]/2+mod)%mod;
printf("%d\n",ans);return 0;
}

posted @ 2018-03-29 22:10  租酥雨  阅读(208)  评论(0编辑  收藏  举报