#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
char S[maxn],T[maxn];
struct PT
{
struct in{
int dep,fail,len,son[];
}p[maxn];
int cnt,last;
void init()
{
//memset(p,0,sizeof(p));
cnt=last=;p[].dep=p[].dep=;
p[].fail=p[].fail=;
p[].len=; p[].len=-;
}
int add(int c,int n)
{
int np=last;
while(S[n]!=S[n--p[np].len]) np=p[np].fail;
if(!p[np].son[c]){
int v=++cnt,k=p[np].fail; p[v].len=p[np].len+;
while(S[n]!=S[n-p[k].len-]) k=p[k].fail;
p[v].fail=p[k].son[c];
p[np].son[c]=v; //这一句放前面会出现矛盾,因为np可能=k
p[v].dep=p[p[v].fail].dep+;
}
last=p[np].son[c];
return p[last].dep;
}
}Tree;
int N,M,num[maxn],Next[maxn],extand[maxn]; ll ans;
void getnext(){// next[i]: 以第i位置开始的子串与T的公共前缀长度
int i,length=strlen(T+);
Next[]=length;
for(i=;i+<length&&T[i+]==T[i+];i++);
Next[]=i;
int a=; //!
for(int k=;k<=length;k++){//长度+1,位置-1。
int p=a+Next[a]-, L=Next[k-a+];
if(L>=p-k+){
int j=(p-k+)>?(p-k+):;//中断后可能是负的
while(k+j<=length&&T[k+j]==T[j+]) j++;// 枚举(p+1,length) 与(p-k+1,length) 区间比较
Next[k]=j, a=k;
}
else Next[k]=L;
}
}
void getextand(){
memset(Next,,sizeof(Next));
getnext();
int Slen=strlen(S+),Tlen=strlen(T+),a=;
int MinLen=Slen>Tlen?Tlen:Slen;
while(a<MinLen&&S[a+]==T[a+]) a++;
extand[]=a; a=;
for(int k=;k<=Slen;k++){
int p=a+extand[a]-,L=Next[k-a+];
if(L>=p-k+){
int j=(p-k+)>?(p-k+):;
while(k+j<=Slen&&j+<=Tlen&&S[k+j]==T[j+]) j++;
extand[k]=j;a=k;
}
else extand[k]=L;
}
}
int main()
{
scanf("%s%s",S+,T+);
N=strlen(S+); M=strlen(T+);
reverse(S+,S+N+); Tree.init();
rep(i,,N) num[i]=Tree.add(S[i]-'a',i);
getextand();
rep(i,,N) ans+=(ll)num[i-]*extand[i];
printf("%lld\n",ans);
return ;
}

不知道写什么。。。

Gym - 101981M:(南京) Mediocre String Problem(回文树+exkmp)的更多相关文章

  1. 【HDU5421】Victor and String(回文树)

    [HDU5421]Victor and String(回文树) 题面 Vjudge 大意: 你需要支持以下操作: 动态在前端插入一个字符 动态在后端插入一个字符 回答当前本质不同的回文串个数 回答当前 ...

  2. HDU 5421 Victor and String(回文树)

    Victor and String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/262144 K (Java/Othe ...

  3. 杭电多校HDU 6599 I Love Palindrome String (回文树)题解

    题意: 定义一个串为\(super\)回文串为: \(\bullet\) 串s为主串str的一个子串,即\(s = str_lstr_{l + 1} \cdots str_r\) \(\bullet\ ...

  4. HDU - 5421:Victor and String (回文树,支持首尾插入新字符)

    Sample Input 6 1 a 1 b 2 a 2 c 3 4 8 1 a 2 a 2 a 1 a 3 1 b 3 4 Sample Output 4 5 4 5 11 题意:多组输入,开始字符 ...

  5. HDU - 5157 :Harry and magic string (回文树,求多少对不相交的回文串)

    Sample Input aca aaaa Sample Output 3 15 题意: 多组输入,每次给定字符串S(|S|<1e5),求多少对不相交的回文串. 思路:可以用回文树求出以每个位置 ...

  6. 2018南京网络赛 - Skr 回文树

    题意:求本质不同的回文串(大整数)的数字和 由回文树的性质可知贡献只在首次进入某个新节点时产生 那么只需由pos和len算出距离把左边右边删掉再算好base重复\(O(n)\)次即可 位移那段写的略微 ...

  7. Mediocre String Problem (2018南京M,回文+LCP 3×3=9种做法 %%%千年好题 感谢"Grunt"大佬的细心讲解)

    layout: post title: Mediocre String Problem (2018南京M,回文+LCP 3×3=9种做法 %%%千年好题 感谢"Grunt"大佬的细 ...

  8. ACM-ICPC2018南京赛区 Mediocre String Problem

    Mediocre String Problem 题解: 很容易想到将第一个串反过来,然后对于s串的每个位置可以求出t的前缀和它匹配了多少个(EXKMP 或者 二分+hash). 然后剩下的就是要处理以 ...

  9. 2014-2015 ACM-ICPC, Asia Xian Regional Contest G The Problem to Slow Down You 回文树

    The Problem to Slow Down You Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjud ...

随机推荐

  1. python3实现的rtsp客户端脚本

    一.说明 此客户端使用python3编写 此客户端实现RTSP的OPTIONS, DESCRIBE, SETUP , PLAY, GET_PARAMETER,TEARDOWN方法,未实现ANNOUNC ...

  2. cmp的值到底是0还是1还是-1的问题

    返回值不局限于这三个数返回负数,表示第一个参数小于第二个参数返回整数,表示第一个参数大于第二个参数返回0,表示他们相等

  3. 使用C#开发数据库应用程序

    第一章 用Hello ACCP.NET快速热身(一) 1-1.进入C#世界 a.第一个C#程序 (1)新建项目[项目:project] (2)生成解决方案[生成:build,解决方案:solution ...

  4. css 让div 的高度和屏幕的高度一样

    <html><head><title>无标题文档</title><style type="text/css">html, ...

  5. VMware 安装 centos,自定义分区

    具体查看:https://jingyan.baidu.com/album/6525d4b1799149ac7d2e9483.html?picindex=11

  6. Unity中UGUI之Canvas属性解读版本一

    Canvas的基本属性 1.Canvas Scaler组件 : Canvas Scaler组件用于设置处于不同组件下Canvas画布中的元素的缩放模式. Ui Scaler Mode : 设置UI的缩 ...

  7. FFT模板(无讲解)

    #include<bits/stdc++.h> using namespace std; ; const double pi=3.1415926535898; ],len; struct ...

  8. Python Django 之 直接执行自定义SQL语句(二)

    转载自:https://my.oschina.net/liuyuantao/blog/712189 一般来说,最好用 Django 自带的模型来实现这些操作.这里仅仅只是为了学习使用原始 SQL 而做 ...

  9. Cracking The Coding Interview 3.6

    // Write a program to sort a stack in ascending order. You should not make any assumptions about how ...

  10. DevExpress WinForms v18.2新版亮点(二)

    行业领先的.NET界面控件2018年第二次重大更新——DevExpress v18.2日前正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExpress WinForms v1 ...