zoukankan      html  css  js  c++  java
  • BZOJ.3676.[APIO2014]回文串(回文树)

    BZOJ
    洛谷

    很久之前写(抄)过一个Hash+Manacher的做法,当时十分懵逼=-=
    然而是道回文树模板题。

    回文树教程可以看这里(真的挺妙的)。
    顺便再放上MilkyWay的笔记~

    //35100kb	708ms
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #define gc() getchar()
    typedef long long LL;
    const int N=3e5+5;
    
    struct Palindromic_Tree
    {
    	int las,tot,son[N][26],len[N],fail[N],val[N];
    	char s[N];
    
    	Palindromic_Tree() {tot=1, fail[0]=1, len[1]=-1, s[0]='$';}
    	inline int Find(int x,int n)
    	{
    		while(s[n-len[x]-1]!=s[n]) x=fail[x];
    		return x;
    	}
    	void Insert(int c,int n)
    	{
    		int p=Find(las,n);
    		if(!son[p][c])
    		{
    			int np=++tot; fail[np]=son[Find(fail[p],n)][c];
    			son[p][c]=np, len[np]=len[p]+2;
    		}
    		++val[las=son[p][c]];
    	}
    	void Solve()
    	{
    		scanf("%s",s+1); int n=strlen(s+1);
    		for(int i=1; i<=n; ++i) Insert(s[i]-'a',i);
    		LL ans=0;
    		for(int i=tot; i>1; --i)
    			val[fail[i]]+=val[i], ans=std::max(ans,1ll*val[i]*len[i]);
    		printf("%lld
    ",ans);
    	}
    }T;
    
    int main()
    {
    	T.Solve();
    	return 0;
    }
    
  • 相关阅读:
    android 源码
    android 保护
    电池信息 显示
    RGB、HSB、HSL 互相转换算法
    网页美工
    css 设计标准
    js 封闭 小结
    格式转换工具
    网页设计规范
    瀑布流分析
  • 原文地址:https://www.cnblogs.com/SovietPower/p/10270134.html
Copyright © 2011-2022 走看看