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 ...
随机推荐
- 【CUDA】CUDA框架介绍
引用 出自Bookc的博客,链接在此http://bookc.github.io/2014/05/08/my-summery-the-book-cuda-by-example-an-introduct ...
- windows jenkins 发布 springboot项目脚本
windows jenkins 发布 springboot项目脚本 1.关闭现有程序 (按端口关闭) [与按应用关闭 二选一] @echo off for /f "tokens=1-5&q ...
- mysql-jdbc connector
mysql-jdbc connector: https://dev.mysql.com/downloads/connector/j/ 目录: /usr/share/java/mysql-connect ...
- spring boot-3.原理探究
新建的项目结构如下图: 1.POM 文件 项目会默认依赖 spring-boot-starter-parent 项目 <parent> <groupId>org.springf ...
- 开发完成的springboot项目扩展 swagger
第一步:pom.xml 引入 swagger 配置 <swagger.version>2.9.2</swagger.version> <!--swagger start- ...
- Redis 3主-3从集群的搭建(CentOS 7)
注意ip地址为: 虚拟机ip设置 TYPE="Ethernet"BOOTPROTO="static"NAME="enp0s3"DEVICE= ...
- Git介绍、安装、命令和实战
一.Git介绍 Git是一个开源的分布式版本控制系统,可以有效.高速地处理从很小到非常大的项目版本管理. 二.Git安装(Mac系统) 在Git官网下载安装包双击直接安装 在终端输入git来检测Git ...
- Java 读取Json文件内容
读取json文件为String类型: import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logge ...
- 洛谷 P1508 Likecloud 题解
题面 很简单的一个二维DP f[i][j]表示最后吃到(i,j)所能获得的最大值, 那么f[i][j]=max(f[i+1][j-1],f[i+1][j],f[i+1][j+1])+a[i][j]; ...
- gcc数据结构对齐之:why.
gcc 支持 aligned 和 packed 属性指定数据对齐,那么在了解对齐规则之前,需要解决第一个以为,我们为什么需要数据对齐?请看下图: 相信学过汇编的朋友都很熟悉这张图,这张图就是CPU与内 ...