#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. provider和consumer配置参数的优先级

    <dubbo:service>和<dubbo:reference>存在一些相同的参数,例如:timeout,retries等,那么哪个配置的优先级高呢? consumer合并u ...

  2. js简单验证码的生成和验证

    如何用js生成简单验证码,并验证是否正确的方法 1.html页面如下 <div> <table border="0" cellspacing="5&qu ...

  3. mysql 如何在访问某张数据表按照某个字段分类输出

    也许大家有时候会遇到需要将把数据库中的某张表的数据按照该表的某个字段分类输出,比如一张数据表area如下 我们需要将里面的area按照serialize字段进行分类输出,比如这种形式: areas   ...

  4. linux系统管理 计划任务

    一次性计划任务 命令: at 语法: at [-f 文件名] 时间 绝对计时方法 HH:MM yyyy-MM-dd 相对计时方法 now + n minutes now+n hours now + n ...

  5. bzoj1294

    题解: 首先发现假如一个豆豆被多边形围住了,那么从这个豆豆引出一条射线 会有奇数个焦点 然后我们从每个豆豆引出一条射线 然后状压dfs 代码: #include<bits/stdc++.h> ...

  6. OO Summary Ⅳ

    测试与正确性论证的效果差异 测试,或者说用断言进行黑箱测试,用大量的数据进行“覆盖性测试”,目的是当分支覆盖率达到100%也就是理论上来说所有可能的输入都已经测试过了,而输出结果均是正确的,那么我们理 ...

  7. day056 多表增加和查询

    今日总结: 多表的增删改查操作 多表操作 增 book id title book_detail publish author onetoone manytoone manytomany book_o ...

  8. 【转载三】Grafana系列教程–Grafana的配置及运行

    本篇文章,就让我们来了解下,Grafana的简单配置及运行. 详细的配置我们后面会讲,本篇文章只对其配置做一个简单了解,主要是让大家了解Grafana的配置及启动的过程及方法. 更多Grafana问题 ...

  9. netty源码理解(一):new一个NioEventLoopGroup的时候做了哪些事

    好了,回到构造方法的调用中

  10. AMR11A - Magic Grid

    Thanks a lot for helping Harry Potter in finding the Sorcerer's Stone of Immortality in October. Did ...