P1659 [国家集训队]拉拉队排练 1.思维误区:长度为5的最大回文串一定也是长度为3的回文串!! 2.快速幂,和取模这样的技巧处理不好,会很容易wa,并且还不知道自己错在哪。 3. ans[p[i]-1]++;
回文串的长度统计.由于区间的对称性,和算法对于回文串的特殊处理,p[i]-1
就是该字符在原串中的回文长度。
#include
#define int long long
using namespace std;
const int maxn=5e6+5;
const int mod=19930726;
string s;
int p[maxn],n,k,ans[maxn],g;
bool cmp(int x,int y)
{
return x>y;
}
int fastpow(int x,int y)
{
int tmp=1;
while(y){
if(y&1)
tmp*=x,tmp%=mod;
x*=x,x%=mod;
y>>=1;
}
return tmp;
}
void manacher()
{
string ss="@#";
for(int i=0;in>>k>>s;
manacher();
int tmp=1,sum=0;
for(int i=n;i>=1;i--)
{
if(i%2==0) continue;
sum+=ans[i];
if(k>=sum)
{
tmp*=fastpow(i,sum);
tmp%=mod,k-=sum;
}
else
{
tmp*=fastpow(i,k),tmp%=mod;
k-=sum;break;
}
}
if(k>0)
cout
关注
打赏