建一个广义后缀自动机统计一下就行,好长时间不敲后缀自动机调了半天~

#include <bits/stdc++.h>
using namespace std;
namespace IO {
void setIO(string s) {
string in=s+".in";
freopen(in.c_str(),"r",stdin);
}
};
#define ll long long
const int maxn=600004;
const ll mod=1000000007;
int last,tot;
int ch[maxn][30],f[maxn],len[maxn],n[4],rk[maxn],tax[maxn];
ll answer[maxn], cnt[maxn][4];
char A[maxn];
void extend(int c,int i) {
int p=last;
if(ch[p][c]) {
int q=ch[p][c];
if(len[q]==len[p]+1) last=q;
else {
int nq=++tot;
last=nq,len[nq]=len[p]+1;
memcpy(ch[nq],ch[q],sizeof(ch[q]));
f[nq]=f[q],f[q]=nq;
while(p&&ch[p][c]==q) ch[p][c]=nq,p=f[p];
}
}
else {
int np=++tot;
len[np]=len[p]+1,last=np;
while(p&&!ch[p][c]) ch[p][c]=np,p=f[p];
if(!p) f[np]=1;
else {
int q=ch[p][c];
if(len[q]==len[p]+1) f[np]=q;
else {
int nq=++tot;
len[nq]=len[p]+1;
memcpy(ch[nq],ch[q],sizeof(ch[q]));
f[nq]=f[q],f[np]=f[q]=nq;
while(p&&ch[p][c]==q) ch[p][c]=nq,p=f[p];
}
}
}
++cnt[last][i];
}
int main() {
// IO::setIO("input");
last=tot=1;
int i,j;
for(i=0;i<3;++i) {
scanf("%s",A+1), n[i]=strlen(A+1),last=1;
for(j=1;j<=n[i];++j) extend(A[j]-'a',i);
}
for(i=1;i<=tot;++i) ++tax[len[i]];
for(i=1;i<=tot;++i) tax[i]+=tax[i-1];
for(i=1;i<=tot;++i) rk[tax[len[i]]--]=i;
for(i=tot;i>=2;--i) {
int cur=rk[i];
for(j=0;j<3;++j) cnt[f[cur]][j]+=cnt[cur][j];
ll now=cnt[cur][0]*cnt[cur][1]%mod*cnt[cur][2]%mod;
answer[len[f[cur]]+1]=(answer[len[f[cur]]+1]+now)%mod;
answer[len[cur]+1]=(answer[len[cur]+1]-now+mod)%mod;
}
for(i=1;i<=tot;++i) answer[i]+=answer[i-1],answer[i]%=mod;
for(i=1;i<=min(n[0],min(n[1],n[2]));++i) printf("%lld ",answer[i]);
return 0;
}

  

CF452E Three strings 广义后缀自动机的更多相关文章

  1. E. Three strings 广义后缀自动机

    http://codeforces.com/problemset/problem/452/E 多个主串的模型. 建立一个广义后缀自动机,可以dp出每个状态的endpos集合大小.同时也维护一个R[]表 ...

  2. codeforces 204E. Little Elephant and Strings(广义后缀自动机,Parent树)

    传送门在这里. 大意: 给一堆字符串,询问每个字符串有多少子串在所有字符串中出现K次以上. 解题思路: 这种子串问题一定要见后缀自动机Parent树Dfs序统计出现次数都是套路了吧. 这道题统计子串个 ...

  3. MemSQL Start[c]UP 2.0 - Round 1 E - Three strings 广义后缀自动机

    E - Three strings 将三个串加进去,看每个节点在三个串中分别出现了多少次. #include<bits/stdc++.h> #define LL long long #de ...

  4. CodeForces-204E:Little Elephant and Strings (广义后缀自动机求出现次数)

    The Little Elephant loves strings very much. He has an array a from n strings, consisting of lowerca ...

  5. POJ3080 POJ3450Corporate Identity(广义后缀自动机||后缀数组||KMP)

    Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...

  6. SPOJ8093Sevenk Love Oimaster(广义后缀自动机)

    Oimaster and sevenk love each other.     But recently,sevenk heard that a girl named ChuYuXun was da ...

  7. POJ3294Life Forms(广义后缀自动机)(后缀数组+二分+数状数组)

    You may have wondered why most extraterrestrial life forms resemble humans, differing by superficial ...

  8. BZOJ2780 [Spoj]8093 Sevenk Love Oimaster 【广义后缀自动机】

    题目 Oimaster and sevenk love each other. But recently,sevenk heard that a girl named ChuYuXun was dat ...

  9. [bzoj2780][Spoj8093]Sevenk Love Oimaster_广义后缀自动机

    Sevenk Love Oimaster bzoj-2780 Spoj-8093 题目大意:给定$n$个大串和$m$次询问,每次给出一个字符串$s$询问在多少个大串中出现过. 注释:$1\le n\l ...

随机推荐

  1. mysql的最左索引匹配原则

    最近复习数据库,主要看的是mysql.很多东西忘得一干二净.看到某乎上有个答案非常给力,就记录一下,以后方便查看. 链接:https://www.zhihu.com/question/36996520 ...

  2. Python新手练手项目

    1.新手练手项目集中推荐 https://zhuanlan.zhihu.com/p/22164270 2.Python学习网站 https://www.shiyanlou.com 3.数据结构可视化学 ...

  3. Berland Army CodeForces - 883B (贪心,拓扑排序)

    大意: n个点, 点$i$的等级为$r_i$, 只给出部分点的$r$值, $r_i$的范围为[1,k], 且[1,k]都至少有一个. 给定m条有向边, (x,y)表示$r[x]>r[y]$, 求 ...

  4. [Vue] vue-router-interview

    1.vue-router 怎么重定向页面? 路由中配置 redirect 属性 使用路由的别名来完成重定向 2.vue-router 怎么配置 404 页面? path: '*',放在最后一个 3.切 ...

  5. springboot导包spring-boot-starter-parent出现错误

    <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot ...

  6. CVS文件导出

    /** * @param $filename 文件名 */ public function exportCxv($filename) { $filename = @iconv('UTF-8', 'GB ...

  7. vue与angular 区别

    1.vue的双向数据绑定是基于 Es5中的getter和setter来实现的,而angular而是由自己实现的一套模板编译规则,需要进行 ‘脏’ 检查,vue则不需要,因此,vue性能上更高一些,但是 ...

  8. :OpenCV人脸识别Fisherface算法源码分析

    https://blog.csdn.net/loveliuzz/article/details/73875904

  9. 基于Apache服务在centos7上搭建文件列表

    参考文献: https://www.cnblogs.com/snake553/p/8856729.html https://blog.csdn.net/yejinxiong001/article/de ...

  10. Spring MVC中的DispatcherServlet作用

    一. DispatcherServlet是前端控制器设计模式的实现,提供Spring Web MVC的集中访问点,而且负责职责的分派,而且与Spring IoC容器无缝集成,从而可以获得Spring的 ...