CF452E Three strings 广义后缀自动机
建一个广义后缀自动机统计一下就行,好长时间不敲后缀自动机调了半天~
#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 广义后缀自动机的更多相关文章
- E. Three strings 广义后缀自动机
http://codeforces.com/problemset/problem/452/E 多个主串的模型. 建立一个广义后缀自动机,可以dp出每个状态的endpos集合大小.同时也维护一个R[]表 ...
- codeforces 204E. Little Elephant and Strings(广义后缀自动机,Parent树)
传送门在这里. 大意: 给一堆字符串,询问每个字符串有多少子串在所有字符串中出现K次以上. 解题思路: 这种子串问题一定要见后缀自动机Parent树Dfs序统计出现次数都是套路了吧. 这道题统计子串个 ...
- MemSQL Start[c]UP 2.0 - Round 1 E - Three strings 广义后缀自动机
E - Three strings 将三个串加进去,看每个节点在三个串中分别出现了多少次. #include<bits/stdc++.h> #define LL long long #de ...
- CodeForces-204E:Little Elephant and Strings (广义后缀自动机求出现次数)
The Little Elephant loves strings very much. He has an array a from n strings, consisting of lowerca ...
- POJ3080 POJ3450Corporate Identity(广义后缀自动机||后缀数组||KMP)
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
- SPOJ8093Sevenk Love Oimaster(广义后缀自动机)
Oimaster and sevenk love each other. But recently,sevenk heard that a girl named ChuYuXun was da ...
- POJ3294Life Forms(广义后缀自动机)(后缀数组+二分+数状数组)
You may have wondered why most extraterrestrial life forms resemble humans, differing by superficial ...
- BZOJ2780 [Spoj]8093 Sevenk Love Oimaster 【广义后缀自动机】
题目 Oimaster and sevenk love each other. But recently,sevenk heard that a girl named ChuYuXun was dat ...
- [bzoj2780][Spoj8093]Sevenk Love Oimaster_广义后缀自动机
Sevenk Love Oimaster bzoj-2780 Spoj-8093 题目大意:给定$n$个大串和$m$次询问,每次给出一个字符串$s$询问在多少个大串中出现过. 注释:$1\le n\l ...
随机推荐
- SheetJS js-xlsx 的使用, exceljs
js-xlsx 官方文档:https://sheetjs.gitbooks.io/docs/#sheetjs-js-xlsx npm xlsx地址:https://www.npmjs.com/pack ...
- HDU 2809 God of War (状压DP)
God of War Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- ucloud建新主机
系统盘默认20G,可调到40不增加费用.需建好主机后关机才能更改. root密码按统一的设 设好主机名,选好分组
- poj2773(欧基里德算法 或 二分+容斥)
题目链接:https://vjudge.net/problem/POJ-2773 题意:给定m,k,求与m互质的第k个数. 思路一:利用gcd(a,b)=gcd(b*t+a,b)知道,与m互质的数是以 ...
- mysql修改max_allowed_packet数据包最大值
在windows环境下!!!! 1.找到my.inc文件,不是你的安装目录路径,是C:\ProgramData\MySQL\MySQL Server 5.7这个路径,注意 ProgramData 文件 ...
- Spring(五)--autowire自动装配和spel
autowire自动装配和spel 1.需要的实体类 2.需要的配置文件 <?xml version="1.0" encoding="UTF-8"?> ...
- ORA-01406:提取的列值被截断 ; SQL Server :将截断字符串或二进制数据
oracle 数据库可以正常连接,表数据也可以正常读取, 但在程序中相同的位置,有时会报错,有时不会报错,有的电脑会报错,有的不会 报错内容为 ORA-01406:提取的列值被截断 查了网上提供的一些 ...
- WAMP中的mysql设置密码
为WAMP中的mysql设置密码密码 WAMP安装好后,mysql密码是为空的,那么要如何修改呢?其实很简单,通过几条指令就行了,下面我就一步步来操作. 1.首先,通过WAMP打开mysql控制台. ...
- Typora---markdown
一级标题 空格 编写内容 有序内容 +Tab 无序内容 -+Tab 代码块 print('hello world!') typora快捷键 标题1==ctrl +1 图片 表格 Ctrl + T 姓名 ...
- PythonDay14
第十四章装饰器 装饰器 # 开放封闭原则- 1.对扩展是开放的- 2.对修改是封闭的# 在不修改源代码和调用方式的情况下,对函数进行扩展# 第一版装饰器def times(func): def ...