BZOJ 2342 [SHOI2011]双倍回文 (回文自动机)
题目大意:略
先建出$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]双倍回文 (回文自动机)的更多相关文章
- 2018.06.30 BZOJ 2342: [Shoi2011]双倍回文(manacher)
2342: [Shoi2011]双倍回文 Time Limit: 10 Sec Memory Limit: 128 MB Description Input 输入分为两行,第一行为一个整数,表示字符串 ...
- BZOJ 2342: [Shoi2011]双倍回文 马拉车算法/并查集
2342: [Shoi2011]双倍回文 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1123 Solved: 408 题目连接 http://w ...
- bzoj 2342: [Shoi2011]双倍回文 -- manacher
2342: [Shoi2011]双倍回文 Time Limit: 10 Sec Memory Limit: 128 MB Description Input 输入分为两行,第一行为一个整数,表示字符 ...
- Manacher || BZOJ 2342: [Shoi2011]双倍回文 || Luogu P4287 [SHOI2011]双倍回文
题面:[SHOI2011]双倍回文 题解:具体实现时,就是在更新mr时维护前半段是回文串的最长回文串就好了 正确性的话,因为到i时如果i+RL[i]-1<=mr,那么答案肯定在i之前就维护过了: ...
- BZOJ 2342 [Shoi2011]双倍回文(manacher+并查集)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2342 [题目大意] 记Wr为W串的倒置,求最长的形如WWrWWr的串的长度. [题解] ...
- BZOJ 2342 [Shoi2011]双倍回文(Manacher)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2342 题意:求最长子串使得它有四个相同的回文串SSSS相连组成. 首先跑一边Manach ...
- BZOJ 2342: [Shoi2011]双倍回文 [Manacher + set]
题意: 求最长子串使得它有四个相同的回文串SSSS相连组成 枚举中间x 找右边的中间y满足 y-r[y]<=x y<=x+r[x]/2 用个set维护 注意中间只能是# #include ...
- bzoj 2342 [Shoi2011]双倍回文(manacher,set)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2342 [题意] 求出形如w wR w wR的最长连续子串. [思路] 用manache ...
- BZOJ 2342: [Shoi2011]双倍回文
Sol Manacher. 非常裸的Manacher啊...为什么有那么多人写Manacher+并查集?Set?Treap?...好神奇... 你只需要在 \(p[i]++\) 的位置加上判断就可以了 ...
随机推荐
- Bonjour/Zeroconf with Arduino
转自:http://gkaindl.com/software/arduino-ethernet/bonjour Bonjour/Zeroconf with Arduino DownloadVersio ...
- luogu P4756 Added Sequence(凸包+思维)
一眼望去不会. 考虑问题中的\(f(i,j)=|\sum_{p=i}^{j}a_p |\)的实际意义. 其实就是前缀和相减的绝对值. \(f(i,j)=|\ sum[j]-sum[i-1]\ |\ ...
- jenkins 新增节点的3种方式
1.通过ssh建立节点(在节点机子上要安装好jdk) (1)通过用户+密码建立ssh连接 (2)通过用户+密钥建立连接 2.通过jnlp,javaweb的方式连接 (1)创建好节点 (2)在节点的机子 ...
- Spring MVC 的概念1
---恢复内容开始--- SpringMVC是一个采用模型----视图------控制器(MVC)的WEb框架建立在中央前端控制器的 Servlet(DispatcherServlet),他负责发送每 ...
- 【hihocoder 1032】最长回文子串
[题目链接]:http://hihocoder.com/problemset/problem/1032 [题意] [题解] 原文地址:https://segmentfault.com/a/119000 ...
- 配置监听器 服务器启动时 检索常用数据 保存在application中 减少数据的查询操作(OA项目)
模型 大致介绍一下:左侧菜单是用户登录成功之后显示的页面 这些数据就是通过查询数据库 然后在页面中把查到的数据 循环遍历出来 构成了操作菜单 第一个解决的问题:常用数据 在服务器启动的时候 ...
- 0112centos上面l安装卸载mysq
http://www.centoscn.com/CentosServer/sql/2015/0409/5127.html常用命令cat /etc/issuerpm -qa | grep mysqlyu ...
- windows无法开机解决方法
电脑启动弹出错误Ntldr is missing , 解决方法:重新从xp中拷贝一个出来粘贴上就行 电脑启动弹出错误Ntldr is compressed ,表示分区中的文件被压缩了 解决方法:首先把 ...
- CF909B Segments
CF909B Segments 题意翻译 题目描述 给你一个整数N.考虑坐标轴上所有可能的部分,在整数点上的端点,坐标在0到N之间,包括它们. 您希望在几个层中绘制这些片段,这样在每个层中这些片段就不 ...
- Guava工具类
原文链接:http://blog.csdn.net/mnmlist/article/details/53425865 Objects类 Objects类有几个比较不错的方法,toString.hash ...