一道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的更多相关文章

  1. 省队集训day6 C

    Description 给定平面上的 N 个点, 其中有一些是红的, 其他是蓝的.现在让你找两条平行的直线, 使得在保证    不存在一个蓝色的点 被夹在两条平行线之间,不经过任何一个点, 不管是蓝色 ...

  2. 省队集训day6 A

    code: #include<cstdio> #include<iostream> #include<cmath> #include<cstring> ...

  3. 省队集训 Day6 序列

    [题目大意] 给出$n$个数的序列$a_1, a_2, ..., a_n$,有$m$次操作,为下面三种: $A~l~r~d$:区间$[l,r]$,全部加$d$. $M~l~r~d$:区间$[l,r]$ ...

  4. HN2018省队集训

    HN2018省队集训 Day1 今天的题目来自于雅礼的高二学长\(dy0607\). 压缩包下载 密码: 27n7 流水账 震惊!穿着该校校服竟然在四大名校畅通无阻?霸主地位已定? \(7:10\)从 ...

  5. JS省队集训记

    不知不觉省队集训已经结束,离noi也越来越近了呢 论考前实战训练的重要性,让我随便总结一下这几天的考试 Day 1 T1 唉,感觉跟xj测试很像啊?meet in middle,不过这种题不多测是什么 ...

  6. LOJ #6074. 「2017 山东一轮集训 Day6」子序列

    #6074. 「2017 山东一轮集训 Day6」子序列 链接 分析: 首先设f[i][j]为到第i个点,结尾字符是j的方案数,这个j一定是从i往前走,第一个出现的j,因为这个j可以代替掉前面所有j. ...

  7. [2018HN省队集训D9T1] circle

    [2018HN省队集训D9T1] circle 题意 给定一个 \(n\) 个点的竞赛图并在其中钦定了 \(k\) 个点, 数据保证删去钦定的 \(k\) 个点后这个图没有环. 问在不删去钦定的这 \ ...

  8. [2018HN省队集训D8T1] 杀毒软件

    [2018HN省队集训D8T1] 杀毒软件 题意 给定一个 \(m\) 个01串的字典以及一个长度为 \(n\) 的 01? 序列. 对这个序列进行 \(q\) 次操作, 修改某个位置的字符情况以及查 ...

  9. [2018HN省队集训D8T3] 水果拼盘

    [2018HN省队集训D8T3] 水果拼盘 题意 给定 \(n\) 个集合, 每个集合包含 \([1,m]\) 中的一些整数, 在这些集合中随机选取 \(k\) 个集合, 求这 \(k\) 个集合的并 ...

随机推荐

  1. Codeforces Round #260 (Div. 1) --B. A Lot of Games (Trie)

    B. A Lot of Games Andrew, Fedor and Alex are inventive guys. Now they invent the game with strings f ...

  2. 【Cocos2d-X开发学习笔记】第27期:游戏背景之贴图地图类(CCTileMapAtlas)的使用

    本系列学习教程使用的是cocos2d-x-2.1.4(最新版为3.0alpha0-pre) ,PC开发环境Windows7,C++开发环境VS2010 一.贴图地图类CCTileMapAtlas 除了 ...

  3. 快速查询本机IP 分类: windows常用小技巧 2014-04-15 09:28 138人阅读 评论(0) 收藏

    第一步: 点击windows建(屏幕左下方),在搜索程序和文件文本框内输入:cmd 第二步:      点击Enter建进入. 第三步: 输入:ipconfig即可. 版权声明:本文为博主原创文章,未 ...

  4. Node.js连接数据库

    Node.js连接数据库前,须要安装对应的包.假设安装sql server 须要先装包node-sqlserver. 我们以mysql为案例来说明node.js查询mysql数据. 1.安装 node ...

  5. Git客户端(Windows系统)的使用

    本文环境: 操作系统:Windows XP SP3 Git客户端:TortoiseGit-1.8.5.0-32bit 一.安装Git客户端 全部安装均采用默认! 1. 安装支撑软件 msysgit:  ...

  6. MyEclipse 安装SVN插件方法及插件下载地址

    直接解压法 下载地址:http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID=2240下载SVN插件:site-1.x.x. ...

  7. ie兼容CSS3渐变写法

    在css3之前要想做背景色渐变就只能采用添加背景图片的方法,但是随着css3:linear-gradient属性的出现,就可以避免使用添加背景图片的方法,从而优化了性能.但是inear-gradien ...

  8. CentOS修改SSH默认端口

    1. 修改配置文件 vim /etc/ssh/sshd_config 修改 #Port 22 这行,  去掉 #  修改后面的端口号 例如 Port 2123 重启sshd服务 /etc/init.d ...

  9. Activity 【生命周期】

    不同情况下的回调 我们打开应用时先后调用了onCreate()->onStart()->onResume 当我们按BACK键时,我们这个应用程序将结束,这时候我们将先后调用onPause( ...

  10. Cookie的读写

    记住怎么写就可以了,不要问我为什么=_= 设置值的页面:context.Response.SetCookie(new HttpCookie("username",username) ...