首页 > 其他分享 >【模板】最长回文串长度 manacher

【模板】最长回文串长度 manacher

时间:2022-11-07 15:23:46浏览次数:56  
标签:int manacher pa include buf 模板 回文

\(pa_i\) 表示以 \(i\) 为中心的(原串的)回文串长度

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
int n,m,pa[22000010];
char buf[11000010],a[22000010];
void manacher(char *a){
    int len=strlen(a+1);
    for(int i=1,mid=0,r=0;i<=len;i++){
        if(i<=r) pa[i]=min(pa[mid*2-i],r-i);
        while(a[i-pa[i]-1]==a[i+pa[i]+1]) pa[i]++;
        if(i+pa[i]>r) r=i+pa[mid=i]; 
    }
}
int main(){
//  #ifdef LOCAL
//      freopen("input.in","r",stdin);
//  #endif
    scanf("%s",buf+1),n=strlen(buf+1);
    a[0]='~',a[m=1]='|';
    for(int i=1;i<=n;i++) a[++m]=buf[i],a[++m]='|';
    a[++m]=0;
    printf("%d\n",manacher(a));
    return 0;
}

标签:int,manacher,pa,include,buf,模板,回文
From: https://www.cnblogs.com/caijianhong/p/template-manacher.html

相关文章

  • Elasticsearch拼音搜索:自定义分词器的模板
    PUT/test{"settings":{"analysis":{"analyzer":{"my_analyzer":{"tokenizer":"ik_max_word","filter":"py"}......
  • 通用模板对象池-转载
    一个很好用的对象池,分享一下,原文链接:https://www.cnblogs.com/hnxxcxg/p/3191622.html//标准模板unituObjPools;interfaceusesClasses,SysUtils,UntThreadTimer,......
  • 【模板】广义后缀自动机 exSAM
    postedon2022-11-0218:51:48|under模板|sourcesolution膜拜@xzzduang。我们重学一个SAM。一个点维护的是所有\(endpos=S\)的(本质不同的)串,显然这些串的长度......
  • 【模板】二元一次不定方程 exgcd
    postedon2022-09-1715:59:26|under模板|sourcecodeLLmod(LLx,LLm){return(x%m+m)%m;}LLexgcd(LLa,LLb,LLc,LL&x,LL&y){ if(!b)returnx=c/a,y=0,a;......
  • 【模板】二维数点
    postedon2022-10-2313:50:24|under模板|sourceproblem给定一个二维平面,多次询问\(x\in[l_x,r_x],y\in[l_y,r_y]\)的点有多少个。solution1(静态+在线):可持久化......
  • 【模板】网络流
    postedon2022-08-1214:14:05|under模板|source感谢讲师LQS带来的网络流专题。本文非常不严谨,请不要把它当作入门博客。0xFF目录0x00网络流及求法0x01......
  • 【模板】多项式乘法 FFT
    postedon2022-08-0223:57:12|under模板|source涉世不深,不会卡常,恳求大佬指教typedefcomplex<double>comp;constdoublePI=acos(-1);template<intN>struct......
  • 【模板】对拍
    postedon2022-10-1813:30:17|under模板|sourceconstchar*name="bit";#include<cstdio>#include<cstring>#include<algorithm>usingnamespacestd;type......
  • 【模板】动态树 Link-Cut Tree
    postedon2022-08-1718:05:59|under模板|sourcetemplate<intN>structlctree{ intval[N+10],sum[N+10],fa[N+10],ch[N+10][2],rev[N+10]; boolgetson(intp)......
  • 【模板】点分治 Centroid Decomposition
    postedon2022-07-2018:59:16|under模板|source0x00模板(P3806)给定\(n,k\)和一棵树,计算\[\sum\limits_{i,j\leqn}[{\ttdist}(i,j)=k]\]即树上距离为\(k\)......