AC自动机模板2
题目
myAC自动机
code
#include #include #include #include #include #include #include #include #include #include #include #define rg register#define il inline#define lst long long#define ldb long double#define N 155#define M 10550using namespace std;const int Inf=1e9;int n,tot,cnt;struct STRING{ char s[75]; int sum,num;}S[N];struct EDGE{ int to,nxt;}ljl[M];int hd[M];char T[1000050];int End[N],sum[M];int trie[M][26],fail[M];il int read(){ rg int s=0,m=0;rg char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')m=1;ch=getchar();} while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); return m?-s:s;}il void init(){ tot=0,cnt=0; memset(hd,0,sizeof(hd)); memset(sum,0,sizeof(sum)); memset(fail,0,sizeof(fail)); memset(trie,0,sizeof(trie));}il void AC_Insert(rg char s[],rg int num){ rg int now=0,L=strlen(s); for(rg int i=0;i
Q; while(!Q.empty())Q.pop(); for(rg int i=0;i<26;++i) if(trie[0][i])Q.push(trie[0][i]); while(!Q.empty()) { rg int now=Q.front();Q.pop(); for(rg int i=0;i<26;++i) if(trie[now][i]) { fail[trie[now][i]]=trie[fail[now]][i]; Q.push(trie[now][i]); } else trie[now][i]=trie[fail[now]][i]; }}il void AC_Query(){ rg int now=0,L=strlen(T); for(rg int i=0;i