BZOJ 3676 & UOJ 103 [Apio2014]回文串

回文树。

目测manacher和后缀搞一搞可以A,不过应该不好写。
回文树大法好:http://blog.csdn.net/lwfcgz/article/details/48739051

忘记开longlong…

#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 300005
using namespace std;
char s[N];
struct node
{
    node *next[27], *suff;
    int len;
    long long tot;
    node()
    {
        memset(next,NULL,sizeof(next));
        suff=NULL;
        len=tot=0;
    }
};
struct PT
{
    int cnt;
    node t[N], *cur, *now;
    void init()
    {
        cnt=2; cur=&t[2];
        t[1].len=-1; t[1].suff=&t[1];
        t[2].len=0;  t[2].suff=&t[1];
    }
    void extend(int c, int pos)
    {
        while(s[pos-1-cur->len]!=c+'a')
            cur=cur->suff;
        if(cur->next[c])
        {
            cur=cur->next[c];
            cur->tot++;
            return;
        }
        now=&t[++cnt];
        now->tot=1;
        now->len=cur->len+2;
        cur->next[c]=now;
        if(now->len==1)
        {
            now->suff=&t[2];
            cur=now;
            return;
        }
        cur=cur->suff;
        while(s[pos-1-cur->len]!=c+'a')
            cur=cur->suff;
        now->suff=cur->next[c];
        cur=now;
    }
    long long count()
    {
        long long re=0;
        for(int i = cnt; i; i--)
        {
            t[i].suff->tot+=t[i].tot;
            re=max(re,t[i].tot*t[i].len);
        }
        return re;
    }
}pt;
int main()
{
    scanf("%s",s+1);
    pt.init();
    for(int i = 1; s[i]; i++)
        pt.extend(s[i]-'a',i);
    long long ans = pt.count();
    printf("%lld\n",ans);
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值