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]++\) 的位置加上判断就可以了 ...
随机推荐
- Project Euler 38 Pandigital multiples
题意: 将192分别与1.2.3相乘: 192 × 1 = 192192 × 2 = 384192 × 3 = 576 连接这些乘积,我们得到一个1至9全数字的数192384576.我们称192384 ...
- spring 组件注册
一.声明配置类和注册 bean /** * 配置类 == applicationContext.xml 配置文件 * @author Administrator * */ //@Configurati ...
- @value 注解获取属性文件中的值
一.属性文件 db.properties name=jack 二.配置文件 applicationContext.xml <!-- 加载配置文件,该节点只能存在一个,所以用 * ,加载所有属性文 ...
- 统制Highcharts中x轴和y轴坐标值的密度
统制Highcharts中x轴和y轴坐标值的密度 www.MyException.Cn 发布于:2012-06-26 10:04:13 浏览:688次 1 控制Highcharts中x轴和y轴坐标值的 ...
- php RSA 简单实现
这是rsa_private_key.pem-----BEGIN PRIVATE KEY----- MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC ...
- WCF4.0 知识点
一些基础概念 SOAP:Simple Object Access Protocol,简单对象访问协议,基于XML的可扩展消息信封格式,需同事绑定一个网络传输协议. UDDI:用来发布和搜索web服务的 ...
- net--技术栈(大图)
- cocos2d-x 3.0游戏实例学习笔记《卡牌塔防》第一步---開始界面&关卡选择
/* 说明: **1.本次游戏实例是<cocos2d-x游戏开发之旅>上的最后一个游戏,这里用3.0重写并做下笔记 **2.我也问过木头本人啦.他说:随便写,第一别全然照搬代码:第二能够说 ...
- hdu(2846)Repository
Problem Description When you go shopping, you can search in repository for avalible merchandises by ...
- 2015.04.20,外语,读书笔记-《Word Power Made Easy》 11 “如何辱骂敌人” SESSION 30
1.brothers and sisters, wives and husbands Frater: brothers; soror: sister; uxor: wife; maritus: hus ...