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 ...
随机推荐
- 【Qt开发】qt中涉及到空格包含路径的解决办法
qt中涉及到空格路径,qmake是无法正确编译的. 需要在空格路径前面加上$$quote INCLUDEPATH += $$quote(C:/Program Files/MySQL/MySQL Ser ...
- vue --》路由query 编程式导航传值与监听
1.首先在一个页面设置一个按钮,用于路由跳转 <template> <div> <button @click="handleToRouter"> ...
- Java 注解:@PostConstruct和@PreConstruct
从Java EE5规范开始,Servlet增加了两个影响Servlet生命周期的注解(Annotation):@PostConstruct和@PreConstruct.这两个注解被用来修饰一个非静态的 ...
- vs资源视图加载失败
原因:引用了未知的资源,通过打开时报的错可以定位然后修改
- sqlserver with(nolock)而mysql 不需nolock
nolock 是 SQL Server 特有的功能. 例如:对于一个表 A,更新了一行,还没有commit,这时再select * from A 就会死锁.用select * from A(noloc ...
- Appium+Python之获取toast
思考:手机APP上的必填或错误文本提示一般1-2s就会消失,比较难定位,所以一般的固定元素定位方式是不可用的,那我们如何定位toast呢? 前提:1.Appium1.6.3以上(包括1.6.3) 2. ...
- semantic-ui的表单使用
semantic-ui 的表单使用 最近找了一款ui库,jquery可以使用的.可以进行个性化定制,感觉还不错. 现状 简单阐述下该ui的现状吧,目前止步于2.4的版本,github商讨了一波.大致是 ...
- C++ bool、三目运算符、引用
bool变量: C++相对于C语言加入了bool变量,其值为true(1) 和 false(0).true表示不为零的数 false表示为零的数,占用一个字节的空间. 代码: /* 编译环境 gc ...
- Win7 MongoDB可视化工具Robo 3T 1.2.1(robomongo)的安装使用
软件版本: Robo 3T 1.2.1 下载网址: https://robomongo.org/campaign 进入robomongo官网,点击download,进入下载页面 这里选择下载 Robo ...
- 在ubuntu上使用Openresty+lua实现WAF----折腾笔记
1.1 参考loveshell的waf实现思路,再此感谢下面其中一部分是转载 1.2 WAF的功能 支持IP白名单和黑名单功能,直接将黑名单的IP访问拒绝.支持URL白名单,将不需要过滤的URL进行定 ...