题面

传送门

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. 链路层寻址与 ARP

    一. MAC 地址 不是主机或路由器具有链路层地址,而是它们的适配器(即网络接口)具有链路层地址.因此,具有多个网络接口的主机或路由器将具有与之相关联的多个链路层地址. 然而,链路层交换机并不具有与它 ...

  2. js 弹性导航

    <style> *{margin:0;padding:0;} #box{height:50px;float:left;position:relative;background:#f90;} ...

  3. Mac 10.12安装SVN工具SmartSVM 7.6

    说明:SVN工具没有最好的,只有用的最顺手的. 下载: (链接: https://pan.baidu.com/s/1dFGqEsT 密码: uyjx)

  4. linux安装oracle 报错[INS-20802] Oracle Net Configuration Assistant failed 解决办法

    [INS-20802] Oracle Net Configuration Assistant failed 首先从LinuxIDC.com下载这个补丁包,然后用 unzip p8670579_1120 ...

  5. MySQL 重命名数据库

    首先创建目标库 create database trgdb; 获取所有源库的表名 use information_schema; select table_name from TABLES where ...

  6. 使用nginx反向代理jenkins

    1.在Jenkins 官方网站(http://jenkins-ci.org/)下载最新版本war包.拷贝到 $TOMCAT_HOME/webapps 下(不用解压).启动tomcat服务. 2.找到n ...

  7. CentOS 开启安装EPEL YUM源

    我们用yum安装软件时,经常发现我们的yum源里面没有该软件,需要自己去wget,然后configure,make,make install,太折腾了. 其实,CentOS 还有一个源叫做 EPEL ...

  8. sql在insert时判断有无唯一性冲突

    sql在insert时判断有无唯一性冲突,存在相同主键或唯一索引,则不创建 INSERT INTO table(field1, field2, fieldn) SELECT 'field1', 'fi ...

  9. 使用vue的v-model自定义 checkbox组件

    <template id='c'> <input type="checkbox" :checked="checked" v-on:change ...

  10. mysql导入外部.sql文件时错误

    当前环境: 操作系统:windows 7 mysql版本:5.5.36 MySQL Community Server (GPL) 当我第一次导入.sql文件时报错: mysql> source ...