省队集训day6 B
一道AC自动机题····
一定要把一个节点没有的儿子接到它fai的儿子,否则会卡到n^2的·······
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<ctime>
#define maxn 1048580
#define maxl 10005
using namespace std;
typedef long long int64;
char ch,s[maxl];
int fuckwmj=;
int n,l,head,tail,list[maxn];
int64 len;
struct Map{
int n,ans,ind[maxn],tot,now[maxn],son[maxn<<],pre[maxn<<],dep[maxn];
void init(int idx){
n=idx,ans=tot=;
memset(ind,,sizeof(ind));
memset(now,,sizeof(now));
memset(dep,,sizeof(dep));
}
void put(int a,int b){pre[++tot]=now[a],now[a]=tot,son[tot]=b,ind[b]++;}
void solve(){
head=,tail=;
for (int i=;i<=n;i++) if (!ind[i]) list[++tail]=i,dep[i]=;
while (head<tail){
int u=list[++head];
for (int p=now[u],v=son[p];p;p=pre[p],v=son[p]){
ind[v]--,dep[v]=max(dep[v],dep[u]+);
if (!ind[v]) list[++tail]=v;
}
}
for (int i=;i<=n;i++) if (ind[i]){puts("Yes");return;}
for (int i=;i<=n;i++) ans=max(ans,dep[i]);
if (ans>=len) puts("Yes");
else puts("No");
}
}dag;
struct trie{
int idx,son[maxn][],fai[maxn];
bool ok[maxn],bo[maxn];
void clear(){
idx=;
memset(son,,sizeof(son));
memset(fai,,sizeof(fai));
memset(ok,,sizeof(ok));
memset(bo,,sizeof(bo));
}
void insert(){
int p=;
for (int i=,op=(s[i]=='T');i<=l;p=son[p][op],i++,op=(s[i]=='T'))
if (!son[p][op]) son[p][op]=++idx;
ok[p]=;
}
void get_fai(){
head=,tail=,list[]=,fai[]=-,bo[]=;
while (head<tail){
int u=list[++head];
for (int ch=,v=son[u][ch],t;ch<=;v=son[u][++ch])
if (v&&!bo[v]){
bo[v]=,list[++tail]=v;
for (t=fai[u];t>=&&!son[t][ch];t=fai[t]);
if (t>=) fai[v]=son[t][ch]; else fai[v]=;
if (!son[v][]) son[v][]=son[fai[v]][];
if (!son[v][]) son[v][]=son[fai[v]][];
ok[v]=ok[v]|ok[u]|ok[fai[v]];
}
}
dag.init(idx);
head=,tail=,list[]=,bo[]=;
memset(bo,,sizeof(bo));
while (head<tail){
int u=list[++head];
for (int ch=,v=son[u][ch];ch<=;v=son[u][++ch])
if (v&&!ok[v]){
dag.put(u,v);
if (!bo[v]) bo[v]=,list[++tail]=v;
}
}
}
}T;
void get(){
for (ch=getchar();ch!='A'&&ch!='T';ch=getchar());
for (l=;ch=='A'||ch=='T';s[++l]=ch,ch=getchar());
}
int main(){
while (cin>>n>>len){
T.clear();
for (int i=;i<=n;i++) get(),T.insert();
T.get_fai(),dag.solve();
}
return ;
}
省队集训day6 B的更多相关文章
- 省队集训day6 C
Description 给定平面上的 N 个点, 其中有一些是红的, 其他是蓝的.现在让你找两条平行的直线, 使得在保证 不存在一个蓝色的点 被夹在两条平行线之间,不经过任何一个点, 不管是蓝色 ...
- 省队集训day6 A
code: #include<cstdio> #include<iostream> #include<cmath> #include<cstring> ...
- 省队集训 Day6 序列
[题目大意] 给出$n$个数的序列$a_1, a_2, ..., a_n$,有$m$次操作,为下面三种: $A~l~r~d$:区间$[l,r]$,全部加$d$. $M~l~r~d$:区间$[l,r]$ ...
- HN2018省队集训
HN2018省队集训 Day1 今天的题目来自于雅礼的高二学长\(dy0607\). 压缩包下载 密码: 27n7 流水账 震惊!穿着该校校服竟然在四大名校畅通无阻?霸主地位已定? \(7:10\)从 ...
- JS省队集训记
不知不觉省队集训已经结束,离noi也越来越近了呢 论考前实战训练的重要性,让我随便总结一下这几天的考试 Day 1 T1 唉,感觉跟xj测试很像啊?meet in middle,不过这种题不多测是什么 ...
- LOJ #6074. 「2017 山东一轮集训 Day6」子序列
#6074. 「2017 山东一轮集训 Day6」子序列 链接 分析: 首先设f[i][j]为到第i个点,结尾字符是j的方案数,这个j一定是从i往前走,第一个出现的j,因为这个j可以代替掉前面所有j. ...
- [2018HN省队集训D9T1] circle
[2018HN省队集训D9T1] circle 题意 给定一个 \(n\) 个点的竞赛图并在其中钦定了 \(k\) 个点, 数据保证删去钦定的 \(k\) 个点后这个图没有环. 问在不删去钦定的这 \ ...
- [2018HN省队集训D8T1] 杀毒软件
[2018HN省队集训D8T1] 杀毒软件 题意 给定一个 \(m\) 个01串的字典以及一个长度为 \(n\) 的 01? 序列. 对这个序列进行 \(q\) 次操作, 修改某个位置的字符情况以及查 ...
- [2018HN省队集训D8T3] 水果拼盘
[2018HN省队集训D8T3] 水果拼盘 题意 给定 \(n\) 个集合, 每个集合包含 \([1,m]\) 中的一些整数, 在这些集合中随机选取 \(k\) 个集合, 求这 \(k\) 个集合的并 ...
随机推荐
- [Locked] Binary Tree Upside Down
Binary Tree Upside Down Given a binary tree where all the right nodes are either leaf nodes with a s ...
- poj2255
题目大意: 树恢复??树复原?? 小Valentine非常喜欢玩二叉树的游戏,他非常喜欢在二叉树的树根上随机的写上一下大写字母,这是她创造的一个例子: D / \ / \ B E / \ \ / \ ...
- Python里的map、reduce、filter、lambda、列表推导式
Map函数: 原型:map(function, sequence),作用是将一个列表映射到另一个列表, 使用方法: def f(x): return x**2 l = range(1,10) map( ...
- docker安装lnmp 环境
docker基础知识请转 docker中文文档:http://docker-doc.readthedocs.io/zh_CN/latest/index.html docker英文文档: https:/ ...
- ionic2 干货
亲爱的程序员童鞋 分享干货啦 最近在研究ionic2 ,公司也在用ionic2 和typescript,angular2以及cordova做混编APP 我的博客随笔都是随性写的,做了某个功能就想分享一 ...
- QML 语言基础
在<Qt Quick 简单介绍>中我们提到 QML 语法和 Json 相似,请參考<Qt on Android: http下载与Json解析>查看 Json 语法.当然这里我们 ...
- HDOJ 1787 GCD Again(欧拉函数)
GCD Again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 一种解决的方法:CGContextSaveGState: invalid context 0x0
遇到这个问题找了好久答案,最后排错排出来了 CGContextSaveGState: invalid context 0x0. This is a serious error. This applic ...
- 连接管理VMware SphereESXi
连接管理VMware SphereESXi 1. 准备 下载VMware-viclient-all-5.5.0-1993072,并按照提示安装 2. 使用VMware Sphere Client链接事 ...
- codevs 1036 商务旅行 (倍增LCA)
/* 在我还不知道LCA之前 暴力跑的SPFA 70分 三个点TLE */ #include<iostream> #include<cstdio> #include<cs ...