/*
打模板题啊
每个串影响到的集合直接枚举跳parent处理即可 */
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#define ll long long
#define M 400010
#define mmp make_pair
using namespace std;
int read()
{
int x;
cin >> x;
return x;
}
int ch[M][26], fa[M], len[M], cnt = 1, lst, n, m;
string a[M], b; void insert(int c)
{
int p = ++cnt, f = lst;
lst = p;
len[p] = len[f] + 1;
while(f && !ch[f][c]) ch[f][c] = p, f = fa[f];
if(!f)
{
fa[p] = 1;
}
else
{
int q = ch[f][c];
if(len[q] == len[f] + 1)
{
fa[p] = q;
}
else
{
int nq = ++cnt;
fa[nq] = fa[q];
memcpy(ch[nq], ch[q], sizeof(ch[q]));
len[nq] = len[f] + 1;
fa[q] = fa[p] = nq;
while(f && ch[f][c] == q) ch[f][c] = nq, f = fa[f];
}
}
}
int cor[M], ans[M];
int main()
{
ios::sync_with_stdio(false);
n = read(), m = read();
for(int i = 1; i <= n; i++)
{
cin >> a[i];
lst = 1;
for(int j = 0; j < a[i].size(); j++) insert(a[i][j] - 'a');
}
for(int i = 1; i <= n; i++)
{
int now = 1;
for(int j = 0; j < a[i].size(); j++)
{
now = ch[now][a[i][j] - 'a'];
int tmp = now;
while(tmp && cor[tmp] != i) cor[tmp] = i, ans[tmp]++, tmp = fa[tmp];
}
}
while(m--)
{
cin >> b;
int now = 1, as = 0;
for(int i = 0; i < b.size(); i++)
{
now = ch[now][b[i] - 'a'];
if(!now) break;
}
as = ans[now];
cout << as << "\n";
}
return 0;
}

SP8093 JZPGYZ - Sevenk Love Oimaster(SAM)的更多相关文章

  1. SP8093 JZPGYZ - Sevenk Love Oimaster 解题报告

    SP8093 JZPGYZ - Sevenk Love Oimaster 题目大意 给定\(n(n\le 10000)\)个模板串,以及\(m(m\le 60000)\)个查询串(模板串总长\(\le ...

  2. SP8093 JZPGYZ - Sevenk Love Oimaster(广义后缀自动机)

    题意 题目链接 Sol 广义后缀自动机板子题..和BZOJ串那个题很像 首先建出询问串的SAM,然后统计一下每个节点被多少个串包含 最后直接拿询问串上去跑就行了 #include<bits/st ...

  3. SP8093 JZPGYZ - Sevenk Love Oimaster

    传送门 广义后缀自动机-- 其实也不是很难理解,就是每次SAM插入一个串之后,插入新的串的时候,要把last重新调到1的位置,共用一些节点. 这个题我们首先要预处理出来每个状态被多少个串共用.挺暴力的 ...

  4. 【洛谷 SP8093】 JZPGYZ - Sevenk Love Oimaster(后缀自动机)

    题目链接 广义sam.. #include <cstdio> #include <cstring> #include <algorithm> using names ...

  5. SPOJ8093【JZPGYZ - Sevenk Love Oimaster】

    怎么全是广义后缀自动机,我\(AC\)自动机不服 这道题可以使用的算法很多,\(SA\)或者\(SAM\)应该都可以 但是我都不会 但是这毕竟是一个多串匹配问题,\(AC\)自动机还是可以刚一刚的 我 ...

  6. SPOJ 8093 JZPGYZ - Sevenk Love Oimaster

    思路 可以用复杂度不对的做法水过去 相当于求parent树子树中的颜色种数,可以离线后树状数组(HH的项链,询问右端点排序之后维护last),dsu on tree,莫队都可以 但是也可以记录每个点上 ...

  7. BZOJ 2780: [Spoj]8093 Sevenk Love Oimaster [广义后缀自动机]

    JZPGYZ - Sevenk Love Oimaster     Oimaster and sevenk love each other.       But recently,sevenk hea ...

  8. BZOJ 2780: [Spoj]8093 Sevenk Love Oimaster( 后缀数组 + 二分 + RMQ + 树状数组 )

    全部串起来做SA, 在按字典序排序的后缀中, 包含每个询问串必定是1段连续的区间, 对每个询问串s二分+RMQ求出包含s的区间. 然后就是求区间的不同的数的个数(经典问题), sort queries ...

  9. 【BZOJ2780】[Spoj]8093 Sevenk Love Oimaster 广义后缀自动机

    [BZOJ2780][Spoj]8093 Sevenk Love Oimaster Description Oimaster and sevenk love each other.     But r ...

随机推荐

  1. sqoop上传数据到hdfs,并用hive管理数据。

    sqoop导入mysql数据表到HDFS中sqoop import --connect jdbc:mysql://master:3306/test --username root --password ...

  2. 配置中心Client端

    配置中心Client端 1.在Order工程中的Order-Server模块的pom.xml中增加 <dependency> <groupId>org.springframew ...

  3. Redis set数据结构

    set里的数据不能重复 1. 增加set1,值为 a b c d 1 2 3 2. 返回集合元素的数量 3. 重命名set1为set100 4. 查看集合中的成员 5.sdiff set100 set ...

  4. 实践中总结出来对heapq的一点理解

    关于heapq(优先级队列算法): heapq.heapify(x):个人理解就是以线性时间(O(n)时间)将一个list转换经过堆排序之后在放入list中,而这种堆特点是根节点必须小于左右节点.曾听 ...

  5. 使用spark streaming报错ERROR DFSClient: Failed to close inode xxxx

    转载自:http://blog.csdn.net/xiaolixiaoyi/article/details/45875101 好几个Spark streaming的程序同时运行,发现spark报出了如 ...

  6. ML平台_Angel参考

    Angel 是腾讯开源基于参数服务器(Parameter Server)理念的机器学习框架(为支持超大维度机器学习模型运算而生).核心设计理念围绕模型,它将高维度的大模型切分到多个参数服务器节点,并通 ...

  7. ML: 聚类算法R包-网格聚类

    网格聚类算法 optpart::clique optpart::clique CLIQUE(Clustering In QUEst)是一种简单的基于网格的聚类方法,用于发现子空间中基于密度的簇.CLI ...

  8. VTC Fsync_out信号分析

    VTC Fsync_out信号分析 1.GUI配置 Vertical position的值289是根据Frame/Field 0 Vertical settings一栏中sync start来设置的. ...

  9. [转]Scrapy简单入门及实例讲解

    Scrapy简单入门及实例讲解 中文文档:   http://scrapy-chs.readthedocs.io/zh_CN/0.24/ Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用 ...

  10. FastReport问题整理(http://129.sqdj.gov.cn/?p=77)

    1.FastReport中如果访问报表中的对象?可以使用FindObject方法.TfrxMemoView(frxReport1.FindObject(’memo1′)).Text:=’FastRep ...