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 ...
随机推荐
- C++ 结构体重载运算符
听说这个东西有很多种写法什么的,来不及了(要退役了),先整一个之前用到的,可能用到的频率比较高的东西上来. struct node{ ll x,y; }; bool operator < (co ...
- vue-蒙层弹窗里的内容滚动。外层大页面禁止滚动
此需求 有两种方法,第一种,这种方法适用于,底层 和弹窗是两个平行的没有关系的两部分.重叠(https://blog.csdn.net/yuhk231/article/details/741717 ...
- win10 hhctrl.ocx 丢失
1.我的是从同事电脑上复制过来的,他电脑也是win102.复制文件“hhctrl.ocx”到系统目录下 32位系统目录为:C:\WINNT\System32:64位系统为C:\Windows\Sys ...
- HDU 2809 God of War (状压DP)
God of War Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Hbase 三维存储
hbase所谓的三维有序存储的三维是指:rowkey(行主键),column key(columnFamily+qualifier),timestamp(时间戳)三部分组成的三维有序存储. 1.row ...
- python-day13(正式学习)
闭包函数 闭包 闭包:闭是封闭(函数内部函数),包是包含(该内部函数对外部作用域而非全局作用域的变量的引用).闭包指的是:函数内部函数对外部作用域而非全局作用域的引用. 额...这里提示一下闭包!=自 ...
- Vim插件YouCompleteMe安装记录(号称最难装的Vim插件?)
使用 PulginInstall 安装就不要想了,如果你没有梯子的话 自己的 ssr 被封,使用的同事的 ss,但是同事设置的加密方式在 linux 上的 ss 应用不支持... 好吧,直接上过程 1 ...
- Oracle及SQLPLUS使用笔记
Oracle及SQLPLUS使用笔记 自己之前粗粗的学过MySQL,学校用的是Oracle,学生使用sqlplus,这是个命令行界面的数据库管理软件(为了学习嘛,不用图形化可以理解),这里记录一些使用 ...
- node.js使用express模块创建web服务器应用
1.安装express模块 在命令行输入 npm install body-parser --save npm install express --save 2.创建app.js文件 /*应用程序入口 ...
- 007-SaltStack之修改salt-minion id
1. 需求背景 之前使用saltstack添加的主机默认使用了hostname作为salt-minion id,而主机名如果没有做规范和规划,是比较难区分属于什么业务或者机器的.我们需要修改salt- ...