题目大意:略

先建出$PAM$

因为双倍回文串一定是4的倍数,所以找出$PAM$里所有$dep$能整除4的节点

看这个串是否存在一个回文后缀,长度恰好为它的一半,沿着$pre$链往上跳就行了

暴跳可能会$T$,所以倍增了跳

如果被卡空间,可以把trs数组当成倍增数组

 #include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N1 500100
#define S1 (N1<<1)
#define ll long long
#define uint unsigned int
#define rint register int
#define dd double
#define il inline
#define inf 0x3f3f3f3f
#define idx(X) (X-'a')
using namespace std; int gint()
{
int ret=,fh=;char c=getchar();
while(c<''||c>''){if(c=='-')fh=-;c=getchar();}
while(c>=''&&c<=''){ret=ret*+c-'';c=getchar();}
return ret*fh;
}
int len;
namespace PAM{
int trs[N1][],pre[N1],dep[N1],la,tot;
void init(){la=tot=,pre[]=pre[]=,dep[]=-;}
int chk(char *str,int i,int p){return str[i-dep[p]-]!=str[i]?:;}
void insert(char *str,int i)
{
int p=la,np,fp,c=idx(str[i]);
while(chk(str,i,p)) p=pre[p];
if(!trs[p][c])
{
np=++tot;
dep[np]=dep[p]+;
fp=pre[p];
while(chk(str,i,fp)) fp=pre[fp];
pre[np]=trs[fp][c];
trs[p][c]=np;
}
la=trs[p][c];
}
int multi()
{
int ans=,i,j,x;
trs[][]=trs[][]=;
trs[][]=trs[][]=;
for(i=;i<=tot;i++) trs[i][]=i,trs[i][]=pre[i];
for(j=;j<=;j++)
for(int i=;i<=tot;i++)
trs[i][j]=trs[ trs[i][j-] ][j-];
for(i=;i<=tot;i++)
if(dep[i]%==)
{
x=i;
for(j=;j>=;j--)
if(dep[trs[x][j]]>=dep[i]/) x=trs[x][j];
if(dep[x]!=dep[i]/) continue;
ans=max(ans,dep[i]);
}
return ans;
}
};
char str[N1]; int main()
{
//freopen("t2.in","r",stdin);
//freopen("a.out","w",stdout);
scanf("%d",&len);
scanf("%s",str+);
PAM::init();
for(int i=;i<=len;i++) PAM::insert(str,i);
printf("%d\n",PAM::multi());
return ;
}

BZOJ 2342 [SHOI2011]双倍回文 (回文自动机)的更多相关文章

  1. 2018.06.30 BZOJ 2342: [Shoi2011]双倍回文(manacher)

    2342: [Shoi2011]双倍回文 Time Limit: 10 Sec Memory Limit: 128 MB Description Input 输入分为两行,第一行为一个整数,表示字符串 ...

  2. BZOJ 2342: [Shoi2011]双倍回文 马拉车算法/并查集

    2342: [Shoi2011]双倍回文 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1123  Solved: 408 题目连接 http://w ...

  3. bzoj 2342: [Shoi2011]双倍回文 -- manacher

    2342: [Shoi2011]双倍回文 Time Limit: 10 Sec  Memory Limit: 128 MB Description Input 输入分为两行,第一行为一个整数,表示字符 ...

  4. Manacher || BZOJ 2342: [Shoi2011]双倍回文 || Luogu P4287 [SHOI2011]双倍回文

    题面:[SHOI2011]双倍回文 题解:具体实现时,就是在更新mr时维护前半段是回文串的最长回文串就好了 正确性的话,因为到i时如果i+RL[i]-1<=mr,那么答案肯定在i之前就维护过了: ...

  5. BZOJ 2342 [Shoi2011]双倍回文(manacher+并查集)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2342 [题目大意] 记Wr为W串的倒置,求最长的形如WWrWWr的串的长度. [题解] ...

  6. BZOJ 2342 [Shoi2011]双倍回文(Manacher)

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2342 题意:求最长子串使得它有四个相同的回文串SSSS相连组成. 首先跑一边Manach ...

  7. BZOJ 2342: [Shoi2011]双倍回文 [Manacher + set]

    题意: 求最长子串使得它有四个相同的回文串SSSS相连组成 枚举中间x 找右边的中间y满足 y-r[y]<=x y<=x+r[x]/2 用个set维护 注意中间只能是# #include ...

  8. bzoj 2342 [Shoi2011]双倍回文(manacher,set)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2342 [题意] 求出形如w wR w wR的最长连续子串. [思路] 用manache ...

  9. BZOJ 2342: [Shoi2011]双倍回文

    Sol Manacher. 非常裸的Manacher啊...为什么有那么多人写Manacher+并查集?Set?Treap?...好神奇... 你只需要在 \(p[i]++\) 的位置加上判断就可以了 ...

随机推荐

  1. 原生ajax的get和post方法封装

    get 方法 function serialize (data) { if (!data) { return ''; } var paris = []; for (var key in data) { ...

  2. Project Euler 16 Power digit sum( 大数乘法 )

    题意: 215 = 32768,而32768的各位数字之和是 3 + 2 + 7 + 6 + 8 = 26. 21000的各位数字之和是多少? 思路:大数乘法,计算 210 × 100 可加速计算,每 ...

  3. 修改linux新建账户时的过期时间

    #!/bin/bash cat << EOF >> /etc/login.defs PASS_MAX_DAYS 90 EOF

  4. django-5-自定义模板过滤器及标签

    <<<代码布局(自定义的代码放哪里)>>> (1)某个app特有的  1.一般放app目录下 固定名为templatetags 的python文件夹里鸭,如果是别的 ...

  5. Profile 动态切换环境

    一.多 Profile 文件我们在主配置文件编写的时候,文件名可以是 application-{profile}.properties/yml默认使用 application.properties 的 ...

  6. mybatis入门截图二

    -------------------- 线程不安全问题 首先明白什么是线程不安全: 举例:struts2中,每个action中都定义了model模型对象(action类中是全局对象的存在  数据域属 ...

  7. 0112centos上面l安装卸载mysq

    http://www.centoscn.com/CentosServer/sql/2015/0409/5127.html常用命令cat /etc/issuerpm -qa | grep mysqlyu ...

  8. iterator遍历list理解

    1.iterator的next()方法返回值,就是你指定的iiterator<>泛型.所以你再强制转换,就可以得到list里的item了,直接是item对象了. 2.list这东西,你ne ...

  9. [Tailwind] Get started with Tailwindcss

    In this lesson, we learn how to generate CSS utility classes from Tailwind's JavaScript config file. ...

  10. Spring进阶之路(10)-Advice简单介绍以及通过cglib生成AOP代理对象

    Advice简单介绍 1. Before:在目标方法运行之前运行织入.假设Before的处理中没有进行特殊的处理.那么目标方法终于会运行,可是假设想要阻止目标方法运行时.能够通过抛出一个异常来实现.B ...