【BZOJ 2754 喵星球上的点名】
Time Limit: 20 Sec Memory Limit: 128 MB
Submit: 2512 Solved: 1092
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
6 8 25 0 24 14 8 6 18 0 10 20 24 0
7 14 17 8 7 0 17 0 5 8 25 0 24 0
4 8 25 0 24
4 7 0 17 0
4 17 0 8 25
Sample Output
2
1
0
1 2
【提示】
事实上样例给出的数据如果翻译成地球上的语言可以这样来看
2 3
izayoi sakuya
orihara izaya
izay
hara
raiz
HINT
【数据范围】
对于30%的数据,保证:
1<=N,M<=1000,喵星人的名字总长不超过4000,点名串的总长不超过2000。
对于100%的数据,保证:
1<=N<=20000,1<=M<=50000,喵星人的名字总长和点名串的总长分别不超过100000,保证喵星人的字符串中作为字符存在的数不超过10000。
Source
【题解】
①我只会后缀数组(AC自动机不熟,后面补上)
②很无脑地做:把所有东西连在一起(加上不同!连接符!),记下bl[i](i位置属于第几个点姓名串)和st[i]第i个点名串的开头位置,枚举串,在sa里往前后找,并统计答案;
③很朴素的去重:记下vis,找到一次就标记;
④数据水了吧
/*2 3
6 8 25 0 24 14 8 6 18 0 10 20 24 0
7 14 17 8 7 0 17 0 5 8 25 0 24 0
4 8 25 0 24
4 7 0 17 0
4 17 0 8 25
喵星人的输出好萌啊~~ Presentation_Error
后缀数组 后缀数组 后缀数组 后缀数组 后缀数组 后缀数组 后缀数组 后缀数组
*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <ctime>
#include <cmath>
#define inf 0x3f3f3f3f
#define ll long long
#define N 500100
#define Maxs 10001
#define mem(f,a) memset(f,a,sizeof(f))
#define Run(i,l,r) for(int i=l;i<=r;i++)
#define Don(i,l,r) for(int i=l;i>=r;i--)
#define Eun(i,u,E,head) for(int i=head[u],v=E[i].v;i!=-1;i=E[i].next,v=E[i].v)
using namespace std;
int n,m;
int s[N],x[N],y[N],c[N],sa[N],Ht[N],Rk[N];
int vis[N],bl[N],st[N],len[N];
int ans1[N],ans2[N];
void Build_sa(int n,int m)
{ Run(i,,m) c[i]=;
Run(i,,n-) c[x[i]=s[i]]++;
Run(i,,m) c[i]+=c[i-];
Don(i,n-,) sa[--c[x[i]]]=i;
int p;
for (int k=;k<=n;k<=){
p=; Run(i,n-k,n-) y[p++]=i;
Run(i,,n-) if (sa[i]>=k) y[p++]=sa[i]-k;
Run(i,,m) c[i]=;
Run(i,,n-) c[x[y[i]]]++;
Run(i,,m) c[i]+=c[i-];
Don(i,n-,) sa[--c[x[y[i]]]]=y[i];
p=; swap(x,y);
x[sa[]]=;
Run(i,,n-){
x[sa[i]]=(y[sa[i]]==y[sa[i-]]&&y[sa[i]+k]==y[sa[i-]+k])? p-: p++;
}
if (p==n) break;
m=p;
}
}
void Build_Ht(int n)
{ Run(i,,n-) Rk[sa[i]]=i;
int k=;
Run(i,,n-){
if (k) k--;
int j=sa[Rk[i]-];
while (s[i+k]==s[j+k]) k++;
Ht[Rk[i]]=k;
}
}
int main()
{ freopen("name.in","r",stdin);
freopen("name.out","w",stdout);
scanf("%d%d",&n,&m);
int tot=;
Run(i,,n){
int num;
scanf("%d",&num);
Run(j,,num) scanf("%d",&s[tot]),s[tot]++,bl[tot++]=i;
scanf("%d",&num);
s[tot++]=Maxs+;
Run(j,,num) scanf("%d",&s[tot]),s[tot]++,bl[tot++]=i;
s[tot++]=Maxs+;
}
Run(i,,m){
int num;
scanf("%d",&num);
st[i]=tot;len[i]=num;
Run(j,,num) scanf("%d",&s[tot]),s[tot++]++;
s[tot++]=Maxs+;
}
s[tot++]=;
Build_sa(tot,Maxs+);
Build_Ht(tot);
Run(i,,m){
int p,q;
p=q=Rk[st[i]];
while (Ht[p]>=len[i]){
int x=bl[sa[--p]];
if (!x) continue;
if (vis[x]!=i) ans1[i]++,ans2[x]++,vis[x]=i;
}
while (Ht[q+]>=len[i]){
int x=bl[sa[++q]];
if (!x) continue;
if (vis[x]!=i) ans1[i]++,ans2[x]++,vis[x]=i;
}
}
Run(i,,m) printf("%d\n",ans1[i]);
Run(i,,n) printf("%d ",ans2[i]);
return ;
}//by tkys_Austin;
【BZOJ 2754 喵星球上的点名】的更多相关文章
- BZOJ 2754 喵星球上的点名(后缀数组)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2754 题意:给出n个字典串,m个询问串.输出每个询问串出现在多少个字典串中.最后输出每个 ...
- BZOJ 2754: [SCOI2012]喵星球上的点名
2754: [SCOI2012]喵星球上的点名 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 649 Solved: 305[Submit][Sta ...
- BZOJ 2754: [SCOI2012]喵星球上的点名 [后缀数组+暴力]
2754: [SCOI2012]喵星球上的点名 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 1906 Solved: 839[Submit][St ...
- BZOJ 2754: [SCOI2012]喵星球上的点名 [AC自动机+map+暴力]
2754: [SCOI2012]喵星球上的点名 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 1902 Solved: 837[Submit][St ...
- BZOJ 2754 SCOI 2012 喵星球上的点名 后缀数组 树状数组
2754: [SCOI2012]喵星球上的点名 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 2068 Solved: 907[Submit][St ...
- BZOJ 2754 【SCOI2012】 喵星球上的点名
题目链接:喵星球上的点名 首先可以发现姓和名两个串就是逗你玩的.在两个串中间插入一个\(10001\),当成一个串做就可以了. 于是我们的问题转化为了: 有\(n\)个串\(A_1,A_2,\dots ...
- BZOJ_2754__[SCOI2012]_喵星球上的点名_(暴力+后缀数组)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=2754 给出n个姓名串和m个点名串.求每个点名串在多少人的姓名中出现过(在名中出现或在姓中出现, ...
- BZOJ2754: [SCOI2012]喵星球上的点名
2754: [SCOI2012]喵星球上的点名 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 680 Solved: 314[Submit][Sta ...
- 【BZOJ2754】喵星球上的点名(AC自动机)
[BZOJ2754]喵星球上的点名(AC自动机) 题面 BZOJ 题解 友情提示:此题请不要在cogs上提交,它的数据有毒 对于点名串构建\(AC\)自动机 然后把名字丢进去进行匹配, 大力统计一下答 ...
随机推荐
- HashMap 和 HashTable 到底哪不同 ?
HashMap 和 HashTable 到底哪不同 ? 2017/05/29 | 分类: 基础技术 | 1 条评论 | 标签: HASHMAP, HASHTABLE 分享到: 原文出处: 程序员赵鑫 ...
- Oracle和MySQL在使用上的区别
1. Oracle是大型数据库而MySQL是中小型数据库,MySQL是开源的而Oracle的价格非常高. 2. Oracle支持大并发,大访问量. 3. 安装所用的空间差别也是很大,MySQL安 ...
- Paper Reading - Im2Text: Describing Images Using 1 Million Captioned Photographs ( NIPS 2011 )
Link of the Paper: http://papers.nips.cc/paper/4470-im2text-describing-images-using-1-million-captio ...
- Maven私有仓库搭建以及使用
一.使用Docker安装Nexus Docker search nexus docker pull docker.io/sonatype/nexus3 mkdir -p /usr/local/nexu ...
- 算法笔记(c++)--求一个数的所有质数因子
算法笔记(c++)--求一个数的所有质数因子 先贴题目: 这题不难,恶心在理解上面.最后看评论知道了怎么回事: 2*2*3*3*5=180 按照这逻辑的话应该输入的数由一系列质数相乘出来,所以每次找到 ...
- 如何成为优秀评级卖家(Top-rated seller)?与超级卖家的区别是
以eBay美国站点为例,要成为优秀评级卖家(Top-rated seller),需满足如下条件: ● 先成为 eBay超级卖家 ● Low DSR (US buyers) <= 0.50% 或 ...
- 使用Scrapy构建一个网络爬虫
记得n年前项目需要一个灵活的爬虫工具,就组织了一个小团队用Java实现了一个爬虫框架,可以根据目标网站的结构.地址和需要的内容,做简单的配置开发,即可实现特定网站的爬虫功能.因为要考虑到各种特殊情形, ...
- spark的数据结构 RDD——DataFrame——DataSet区别
转载自:http://blog.csdn.net/wo334499/article/details/51689549 RDD 优点: 编译时类型安全 编译时就能检查出类型错误 面向对象的编程风格 直接 ...
- LCA最近公共祖先(Tarjan离线算法)
这篇博客对Tarjan算法的原理和过程模拟的很详细. 转载大佬的博客https://www.cnblogs.com/JVxie/p/4854719.html 第二次更新,之前转载的博客虽然胜在详细,但 ...
- 吴恩达机器学习笔记——正规方程(Normal Equation)
问题描述:m examples : (x(1),y(1)), (x(2),y(2)),..., (x(m),y(m)) and n features; 计算方法:θ = (XTX)-1XTy; 计算过 ...