题面

传送门

Sol

广义\(sam\)

每个\(sam\)的状态开\(set\)记录属于哪些串

\(parent\)树上启发式合并\(set\)

然后每个串就在上面走,通过不停地跳\(parent\)树的父亲节点保证大于等于\(k\),贡献就是\(len\)

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll; IL int Input(){
RG int x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
} const int maxn(1e5 + 5);
const int maxm(5e5 + 5); int trans[26][maxm], fa[maxm], tot = 1, last, len[maxm];
int id[maxm], t[maxm], n, k, size[maxm];
set <int> ed[maxm];
set <int> :: iterator it;
string s[maxn]; IL void Extend(RG int c){
RG int p = last, np = ++tot;
len[last = np] = len[p] + 1;
while(p && !trans[c][p]) trans[c][p] = np, p = fa[p];
if(!p) fa[np] = 1;
else{
RG int q = trans[c][p];
if(len[q] == len[p] + 1) fa[np] = q;
else{
RG int nq = ++tot;
fa[nq] = fa[q], len[nq] = len[p] + 1;
for(RG int i = 0; i < 26; ++i) trans[i][nq] = trans[i][q];
fa[np] = fa[q] = nq;
while(p && trans[c][p] == q) trans[c][p] = nq, p = fa[p];
}
}
} int main(RG int argc, RG char *argv[]){
n = Input(), k = Input();
for(RG int i = 1; i <= n; ++i){
cin >> s[i]; last = 1;
for(RG int j = 0, l = s[i].size(); j < l; ++j) Extend(s[i][j] - 'a');
}
for(RG int i = 1; i <= n; ++i)
for(RG int j = 0, nw = 1, l = s[i].size(); j < l; ++j){
nw = trans[s[i][j] - 'a'][nw];
ed[nw].insert(i);
}
for(RG int i = 1; i <= tot; ++i) ++t[len[i]];
for(RG int i = 1; i <= tot; ++i) t[i] += t[i - 1];
for(RG int i = 1; i <= tot; ++i) id[t[len[i]]--] = i;
for(RG int i = tot; i; --i){
RG int x = id[i];
size[x] = ed[x].size();
if(size[x] > size[fa[x]]) swap(ed[x], ed[fa[x]]);
for(it = ed[x].begin(); it != ed[x].end(); ++it)
ed[fa[x]].insert(*it);
}
for(RG int i = 1; i <= n; ++i){
RG ll ans = 0, nw = 1;
for(RG int j = 0, l = s[i].size(); j < l; ++j){
nw = trans[s[i][j] - 'a'][nw];
while(nw != 1 && size[nw] < k) nw = fa[nw];
if(size[nw] >= k) ans += len[nw];
}
printf("%lld ", ans);
}
return 0;
}

Bzoj3277:串的更多相关文章

  1. BZOJ3473&&BZOJ3277串

    BZOJ3473&&BZOJ3277串 题面 自己找去 HINT 对于所有串建立一个广义后缀自动机,对于每一个节点开一个set表示这个节点接受的子串在哪些串里出现过,然后在parent ...

  2. BZOJ3277 串(后缀数组+二分答案+主席树)

    因为不会SAM,考虑SA.将所有串连起来并加分隔符,每次考虑计算以某个位置开始的子串有多少个合法. 对此首先二分答案,找到名次数组上的一个区间,那么只需要统计有多少个所给串在该区间内出现就可以了.这是 ...

  3. BZOJ3277——串

    0.题意:给定你n个字符串,询问每个字符串有多少子串(不包括空串)是所有n个字符串中至少k个字符串的子串(注意包括本身). 1.分析:这个题我问了吴大爷做法 首先建立后缀自动机,然后利用离线搞出每一个 ...

  4. bzoj3277 串 (后缀数组+二分答案+ST表)

    常见操作:先把所有串都连到一起,但中间加上一个特殊的符号(不能在原串中/出现过)作为分割 由于全部的子串就等于所有后缀的所有前缀,那我们对于每一个后缀,去求一个最长的前缀,来满足这个前缀在至少K个原串 ...

  5. bzoj3473: 字符串 && bzoj3277串

    3473: 字符串 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 121  Solved: 53[Submit][Status][Discuss] D ...

  6. 【文文殿下】[BZOJ3277] 串

    Description 字符串是oi界常考的问题.现在给定你n个字符串,询问每个字符串有多少子串(不包括空串)是所有n个字符串中 至少k个字符串的子串(注意包括本身) Input 第一行两个整数n,k ...

  7. BZOJ3277 串 【广义后缀自动机】

    Description 字符串是oi界常考的问题.现在给定你n个字符串,询问每个字符串有多少子串(不包括空串)是所有n个字符串中 至少k个字符串的子串(注意包括本身). Input 第一行两个整数n, ...

  8. bzoj3473字符串&bzoj3277串

    题意:给定n个字符串,询问每个字符串有多少子串(不包括空串)是所有n个字符串中至少k个字符串的子串.注意本质相同的子串多次出现算多次,如1 1 aaa这组数据答案为6,贡献1WA.代码里有些部分是为了 ...

  9. BZOJ3277: 串(广义后缀自动机)

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1196  Solved: 478[Submit][Status][Discuss] Descripti ...

  10. BZOJ3277 串(后缀自动机)

    对多串建立SAM的一种方法是加分隔符.于是加完分隔符建出SAM. 考虑统计出每个节点被多少个串包含.让每个串各自在SAM上跑,跑到一个节点就标记(显然一定会完全匹配该节点,因为是对包含其的串建的SAM ...

随机推荐

  1. 关于iframe切换的问题

    定位不到元素的另一种问题是有这种iframe,所有我们需要切换到该页面中去 1.首先找到这个iframe的位置,像上图有id属性我们直接  iframe = driver.find_element_b ...

  2. 永久激活navicat_premium12.0,支持win32和64位

    1.下载软件以及注册机 链接:https://pan.baidu.com/s/1NGc6YLsgMQRQYEwnGSU16Q   提取码:guno 2.根据自己的电脑位数安装对应的软件,傻瓜式安全(注 ...

  3. c/c++ int,float,short 大小端转换函数

    unsigned int(uint32_t)大小端转换函数 unsigned int BLEndianUint32(unsigned int value) { return ((value & ...

  4. 第五届CCPC河南省赛参赛有感

    10点开始,不过两次推迟了10分钟,也就是10点20开始.然后真的开始了,我还以为还会推迟10分钟. 比赛从密码输错开始,到瞎改代码疯狂提交结束. 输错密码,耽误了一点时间.点开签到题<文本修改 ...

  5. server端获得到client端的IP地址的格式

    使用telnet,ping或其他client连接server端时,server端获得的client端的ip地址取决于client端使用的时ipv4还是ipv6地址. 例: client IPv4地址: ...

  6. Win10 VS2015 静态编译Qt5.6.2源码

    由于VS2015需要CRT等拓展组件,因此把内部编写的工具软件以静态发布,固需要编译Qt源码.Qt5.6.2版本,VS2015,Win10 1.安装python,perl,下载jom 2.改文件com ...

  7. apktook 反编译错误

    Exception in thread "main" brut.androlib.err.UndefinedResObject: resource spec: 0x01010490 ...

  8. Android MediaPlayer 常用方法介绍

    Android MediaPlayer 常用方法介绍 方法:create(Context context, Uri uri) 解释:静态方法,通过Uri创建一个多媒体播放器. 方法:create(Co ...

  9. casperjs问题收集

    1 无妨访问某些页面可能是ssl选项没有使用 casperjs --ignore-ssl-errors=true --ssl-protocol=any 你的测试文件

  10. MarkDown编辑使用指南

    MarkDown Markdown是一种可以使用普通文本编辑器编写的标记语言,通过简单的标记语法,它可以使普通文本内容具有一定的格式. 区块元素 标题title # h1 ## h2 ### h3 # ...