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

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. namespace IO {
  4. void setIO(string s) {
  5. string in=s+".in";
  6. freopen(in.c_str(),"r",stdin);
  7. }
  8. };
  9. #define ll long long
  10. const int maxn=600004;
  11. const ll mod=1000000007;
  12. int last,tot;
  13. int ch[maxn][30],f[maxn],len[maxn],n[4],rk[maxn],tax[maxn];
  14. ll answer[maxn], cnt[maxn][4];
  15. char A[maxn];
  16. void extend(int c,int i) {
  17. int p=last;
  18. if(ch[p][c]) {
  19. int q=ch[p][c];
  20. if(len[q]==len[p]+1) last=q;
  21. else {
  22. int nq=++tot;
  23. last=nq,len[nq]=len[p]+1;
  24. memcpy(ch[nq],ch[q],sizeof(ch[q]));
  25. f[nq]=f[q],f[q]=nq;
  26. while(p&&ch[p][c]==q) ch[p][c]=nq,p=f[p];
  27. }
  28. }
  29. else {
  30. int np=++tot;
  31. len[np]=len[p]+1,last=np;
  32. while(p&&!ch[p][c]) ch[p][c]=np,p=f[p];
  33. if(!p) f[np]=1;
  34. else {
  35. int q=ch[p][c];
  36. if(len[q]==len[p]+1) f[np]=q;
  37. else {
  38. int nq=++tot;
  39. len[nq]=len[p]+1;
  40. memcpy(ch[nq],ch[q],sizeof(ch[q]));
  41. f[nq]=f[q],f[np]=f[q]=nq;
  42. while(p&&ch[p][c]==q) ch[p][c]=nq,p=f[p];
  43. }
  44. }
  45. }
  46. ++cnt[last][i];
  47. }
  48. int main() {
  49. // IO::setIO("input");
  50. last=tot=1;
  51. int i,j;
  52. for(i=0;i<3;++i) {
  53. scanf("%s",A+1), n[i]=strlen(A+1),last=1;
  54. for(j=1;j<=n[i];++j) extend(A[j]-'a',i);
  55. }
  56. for(i=1;i<=tot;++i) ++tax[len[i]];
  57. for(i=1;i<=tot;++i) tax[i]+=tax[i-1];
  58. for(i=1;i<=tot;++i) rk[tax[len[i]]--]=i;
  59. for(i=tot;i>=2;--i) {
  60. int cur=rk[i];
  61. for(j=0;j<3;++j) cnt[f[cur]][j]+=cnt[cur][j];
  62. ll now=cnt[cur][0]*cnt[cur][1]%mod*cnt[cur][2]%mod;
  63. answer[len[f[cur]]+1]=(answer[len[f[cur]]+1]+now)%mod;
  64. answer[len[cur]+1]=(answer[len[cur]+1]-now+mod)%mod;
  65. }
  66. for(i=1;i<=tot;++i) answer[i]+=answer[i-1],answer[i]%=mod;
  67. for(i=1;i<=min(n[0],min(n[1],n[2]));++i) printf("%lld ",answer[i]);
  68. return 0;
  69. }

  

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. 【Qt开发】qt中涉及到空格包含路径的解决办法

    qt中涉及到空格路径,qmake是无法正确编译的. 需要在空格路径前面加上$$quote INCLUDEPATH += $$quote(C:/Program Files/MySQL/MySQL Ser ...

  2. vue --》路由query 编程式导航传值与监听

    1.首先在一个页面设置一个按钮,用于路由跳转 <template> <div> <button @click="handleToRouter"> ...

  3. Java 注解:@PostConstruct和@PreConstruct

    从Java EE5规范开始,Servlet增加了两个影响Servlet生命周期的注解(Annotation):@PostConstruct和@PreConstruct.这两个注解被用来修饰一个非静态的 ...

  4. vs资源视图加载失败

    原因:引用了未知的资源,通过打开时报的错可以定位然后修改

  5. sqlserver with(nolock)而mysql 不需nolock

    nolock 是 SQL Server 特有的功能. 例如:对于一个表 A,更新了一行,还没有commit,这时再select * from A 就会死锁.用select * from A(noloc ...

  6. Appium+Python之获取toast

    思考:手机APP上的必填或错误文本提示一般1-2s就会消失,比较难定位,所以一般的固定元素定位方式是不可用的,那我们如何定位toast呢? 前提:1.Appium1.6.3以上(包括1.6.3) 2. ...

  7. semantic-ui的表单使用

    semantic-ui 的表单使用 最近找了一款ui库,jquery可以使用的.可以进行个性化定制,感觉还不错. 现状 简单阐述下该ui的现状吧,目前止步于2.4的版本,github商讨了一波.大致是 ...

  8. C++ bool、三目运算符、引用

    bool变量: C++相对于C语言加入了bool变量,其值为true(1) 和 false(0).true表示不为零的数  false表示为零的数,占用一个字节的空间. 代码: /* 编译环境  gc ...

  9. Win7 MongoDB可视化工具Robo 3T 1.2.1(robomongo)的安装使用

    软件版本: Robo 3T 1.2.1 下载网址: https://robomongo.org/campaign 进入robomongo官网,点击download,进入下载页面 这里选择下载 Robo ...

  10. 在ubuntu上使用Openresty+lua实现WAF----折腾笔记

    1.1 参考loveshell的waf实现思路,再此感谢下面其中一部分是转载 1.2 WAF的功能 支持IP白名单和黑名单功能,直接将黑名单的IP访问拒绝.支持URL白名单,将不需要过滤的URL进行定 ...