[题目链接]

https://codeforces.com/contest/452/problem/E

[算法]

构建后缀数组

用并查集合并答案即可

时间复杂度 : O(NlogN)

[代码]

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = 3e5 + ;
const int P = 1e9 + ; #define rint register int struct info
{
int id , ht;
} a[N]; int n;
int height[N] , sa[N] , rk[N] , sz[N] , cnta[N] , cntb[N] , cntc[N] , bel[N] , fa[N];
ll ans[N];
char s[N] , s1[N] , s2[N] , s3[N]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void add(T &x , T y)
{
x += y;
while (x >= P) x -= P;
}
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline void build_sa()
{
static int x[N] , y[N] , cnt[N];
for (rint i = ; i <= n; ++i) ++cnt[s[i]];
for (rint i = ; i <= ; ++i) cnt[i] += cnt[i - ];
for (rint i = n; i >= ; --i) sa[cnt[s[i]]--] = i;
rk[sa[]] = ;
for (rint i = ; i <= n; ++i) rk[sa[i]] = rk[sa[i - ]] + (s[sa[i]] != s[sa[i - ]]);
for (rint k = ; rk[sa[n]] != n; k <<= )
{
for (rint i = ; i <= n; ++i)
x[i] = rk[i] , y[i] = (i + k <= n) ? rk[i + k] : ;
for (rint i = ; i <= n; ++i) cnt[i] = ;
for (rint i = ; i <= n; ++i) ++cnt[y[i]];
for (rint i = ; i <= n; ++i) cnt[i] += cnt[i - ];
for (rint i = n; i >= ; i--) rk[cnt[y[i]]--] = i;
for (rint i = ; i <= n; ++i) cnt[i] = ;
for (rint i = ; i <= n; ++i) ++cnt[x[i]];
for (rint i = ; i <= n; ++i) cnt[i] += cnt[i - ];
for (rint i = n; i >= ; i--) sa[cnt[x[rk[i]]]--] = rk[i];
rk[sa[]] = ;
for (rint i = ; i <= n; ++i) rk[sa[i]] = rk[sa[i - ]] + (x[sa[i]] != x[sa[i - ]] || y[sa[i]] != y[sa[i - ]]);
}
}
inline void get_height()
{
int k = ;
for (rint i = ; i <= n; ++i)
{
if (k) --k;
int j = sa[rk[i] + ];
while (s[i + k] == s[j + k]) ++k;
height[rk[i]] = k;
}
}
inline bool cmp(info a , info b)
{
return a.ht > b.ht;
}
inline int get_root(int x)
{
if (fa[x] == x) return x;
else return fa[x] = get_root(fa[x]);
}
inline void merge(int x , int y)
{
if (sz[x] > sz[y]) swap(x , y);
fa[x] = y;
cnta[y] += cnta[x];
cntb[y] += cntb[x];
cntc[y] += cntc[x];
sz[y] += sz[x];
return;
}
inline int _min(int x , int y , int z)
{
return min(min(x , y) , z);
} int main()
{ scanf("%s%s%s" , s1 + , s2 + , s3 + );
int l1 = strlen(s1 + ) , l2 = strlen(s2 + ) , l3 = strlen(s3 + );
for (rint i = ; i <= l1; ++i)
{
s[++n] = s1[i];
bel[n] = ;
}
s[++n] = '#';
for (rint i = ; i <= l2; ++i)
{
s[++n] = s2[i];
bel[n] = ;
}
s[++n] = '@';
for (rint i = ; i <= l3; ++i)
{
s[++n] = s3[i];
bel[n] = ;
}
build_sa();
get_height();
for (rint i = ; i < n; ++i)
{
a[i].id = i;
a[i].ht = height[i];
}
sort(a + , a + n , cmp);
for (rint i = ; i <= n; ++i)
{
fa[i] = i;
sz[i] = ;
if (bel[sa[i]] == ) cnta[i] = ;
if (bel[sa[i]] == ) cntb[i] = ;
if (bel[sa[i]] == ) cntc[i] = ;
}
for (rint i = ; i < n; ++i)
{
int rk = a[i].id , ht = a[i].ht;
if (!ht) break;
int fx = get_root(rk) , fy = get_root(rk + );
add(ans[ht] , 1LL * cnta[fx] * cntb[fx] % P * cntc[fy] % P);
add(ans[ht] , 1LL * cnta[fx] * cntc[fx] % P * cntb[fy] % P);
add(ans[ht] , 1LL * cntb[fx] * cntc[fx] % P * cnta[fy] % P);
add(ans[ht] , 1LL * cnta[fy] * cntb[fy] % P * cntc[fx] % P);
add(ans[ht] , 1LL * cnta[fy] * cntc[fy] % P * cntb[fx] % P);
add(ans[ht] , 1LL * cntb[fy] * cntc[fy] % P * cnta[fx] % P);
merge(fx , fy);
}
for (rint i = n; i >= ; --i) add(ans[i] , ans[i + ]);
for (rint i = ; i <= _min(l1 , l2 , l3); ++i) printf("%lld " , ans[i]);
printf("\n"); return ; }

[Codeforces 452E] Three Strings的更多相关文章

  1. Codeforces 452E Three Strings(后缀自动机)

    上学期很认真地学了一些字符串的常用工具,各种 suffix structre,但是其实对后缀自动机这个部分是理解地不太透彻的,以致于看了师兄A这题的代码后,我完全看不懂,于是乎重新看回一些学习后缀自动 ...

  2. Codeforces 452E Three strings 字符串 SAM

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF542E.html 题目传送门 - CF452E 题意 给定三个字符串 $s1,s2,s3$ ,对于所有 $L ...

  3. Codeforces 868D Huge Strings - 位运算 - 暴力

    You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...

  4. codeforces 112APetya and Strings(字符串水题)

    A. Petya and Strings 点击打开题目 time limit per test 2 seconds memory limit per test 256 megabytes input ...

  5. [Codeforces Round #438][Codeforces 868D. Huge Strings]

    题目链接:868D - Huge Strings 题目大意:有\(n\)个字符串,\(m\)次操作,每次操作把两个字符串拼在一起,并询问这个新串的价值.定义一个新串的价值\(k\)为:最大的\(k\) ...

  6. [Educational Round 5][Codeforces 616F. Expensive Strings]

    这题调得我心疲力竭...Educational Round 5就过一段时间再发了_(:з」∠)_ 先后找了三份AC代码对拍,结果有两份都会在某些数据上出点问题...这场的数据有点水啊_(:з」∠)_[ ...

  7. Codeforces 559B - Equivalent Strings

    559B - Equivalent Strings 思路:字符串处理,分治 不要用substr(),会超时 AC代码: #include<bits/stdc++.h> #include&l ...

  8. Codeforces 112A-Petya and Strings(实现)

    A. Petya and Strings time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  9. CodeForces - 985F Isomorphic Strings

    假如两个区间的26的字母出现的位置集合分别是 A1,B1,A2,B2,....., 我们再能找到一个排列p[] 使得 A[i] = B[p[i]] ,那么就可以成功映射了. 显然集合可以直接hash, ...

随机推荐

  1. Nginx https免费SSL证书配置指南

    生成证书 $ cd /usr/local/nginx/conf $ openssl genrsa -des3 -out server.key 1024 $ openssl req -new -key  ...

  2. 小白学习python之路(二):安装开发工具

    引言 上一章我们安装配置了python3.7,这一章我们安装python的开发工具,我用的pycharm2019 安装 工具连接:https://u20538204.ctfile.com/fs/205 ...

  3. 数据挖掘之Slope One

    计算偏差: card() 表示集合包含的元素数量. http://www.cnblogs.com/similarface/p/5385176.html 论文地址:http://lemire.me/fr ...

  4. Excel COM组件使用的注意事项和一些权限问题(转载)

    1.实例化Excel的COM组件的时候,不要直接调用类,要用Microsoft提供的接口 原来的写法:Excel.ApplicationClass excelApp = new Excel.Appli ...

  5. 给定一颗完全二叉树,给每一层添加上next的指针,从左边指向右边

    给你机会发出声音,但是不给你机会证明高层的决定是错的 RT: 时间复杂度O(n) 空间复杂度O(1)  原理就是有指针指向父节点和当前的节点,左孩子必指向右孩子,右孩子必指向父节点的下一个节点的左孩子 ...

  6. 详解spring boot实现多数据源代码实战

    之前在介绍使用JdbcTemplate和Spring-data-jpa时,都使用了单数据源.在单数据源的情况下,Spring Boot的配置非常简单,只需要在application.propertie ...

  7. 【BZOJ3745】[Coci2015]Norma cdq分治

    [BZOJ3745][Coci2015]Norma Description Input 第1行,一个整数N: 第2~n+1行,每行一个整数表示序列a. Output 输出答案对10^9取模后的结果. ...

  8. EasyNVR RTSP转RTMP-HLS流媒体服务器前端构建之:通过接口获取实时信息

    对于动态网站,要实时更新网站的信息,通过接口来获取实时信息是一个必不可少的部分.EasyNVR可以接入IPC等前端设备,必须要实时获取到对应的IPC实时信息进行展示. 本篇主要说明Ajax来获取数据. ...

  9. 绿色版Tomcat的配置

    在环境变量中不配置JAVA_HOME或者JRE_HONE的情况下(正确配置java的路径)不影响java的使用 可以正常使用 java -version .... 但是这种情况下 无法在Tomcat的 ...

  10. Java I/O模型从BIO到NIO和Reactor模式(转)

    原创文章,转载请务必将下面这段话置于文章开头处(保留超链接).本文转发自技术世界,原文链接 http://www.jasongj.com/java/nio_reactor/ Java I/O模型 同步 ...