Title Description
Original title from: Usaco. Gold
There is a length not exceeding10510^5105 of stringsSsS Farmer John wants toSsS in the EraseNnn Shielding words (a shield Word may appear multiple times), these words are recorded asT1∼tnt_1\sim T_nt< Span class= "msupsub" > 1 ? ∼tn?
FJ inSsS in the beginning to look for a shield word, once found a shield word, FJ Delete it, and then start looking (instead of looking down). FJ will repeat the process untilSss There are no blocking words. Note Deleting a word may cause ss s another screen word appears. This nn n A word that does not appear as another word substring, which means that each mask word in ss s appear in different starting positions, please help FJ complete these operations and output the final ss S
Input format
The first line contains a stringSsS
The second line contains an integerNnn;
Next nn n rows, each line containing a string, section ii i line string is tit_i t i
Output format
One row, after the output operation of the SSS. Ensure that SSS does not become empty strings.
Example Sample input
begintheescapexecutionatthebreakofdawn2escapeexecution
Sample output
beginthatthebreakofdawn
第一眼看到,以为是bzoj3942,然后就被dalao鄙视了
但是这道题的思想和那道题很像,只不过是把操作过程中的KMP换成了AC自动机
只需要在匹配成功后出栈,中级记录一个可持久化的数组,用来存出栈后从Trie树的那个节点开始重新匹配
下面给出代码:
#include <iostream>#include<algorithm>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<cmath>using namespaceStd;inlineintRd () {intx=0, f=1; CharCh=GetChar (); for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') f=-1; for(; isdigit (ch); Ch=getchar ()) x=x*Ten+ch-'0'; returnx*F;} InlinevoidWriteintx) { if(x<0) Putchar ('-'), x=-x; if(x>9) Write (x/Ten); Putchar (x%Ten+'0'); return ;}Chars[1000006];Chara[1000006];intn,len=0;inttrie[1000006][ -];inttot=1;intvis[1000006];voidPre () {intC=1; for(intI=1; i<=len;i++){ inth=a[i]-'a'; if(!trie[c][h]) trie[c][h]=++tot; C=Trie[c][h]; } Vis[c]=Len; return ;}intnxt[1000006];intq[1000006];intL=0, r=0;voidGet_next () {q[++r]=1; for(intI=0; i<= -; i++) trie[0][i]=1; nxt[1]=0; while(l<R) { inth=q[++L]; for(intI=0; i<= -; i++){ if(!trie[h][i]) trie[h][i]=Trie[nxt[h]][i]; Else{Nxt[trie[h][i]]=Trie[nxt[h]][i]; q[++r]=Trie[h][i]; } } } return ;}intsk[1000006];intCnt=0;intloc[1000006];voidsolve () {intM=strlen (s+1); intC=1; for(intI=1; i<=m;i++) {sk[++cnt]=i; inth=s[i]-'a'; inty=Trie[c][h]; if(Trie[c][h]) {if(Vis[trie[c][h]]) {CNT-=Vis[trie[c][h]]; C=Loc[sk[cnt]]; Continue; }} C=y; Loc[i]=y; } return ;}intMain () {scanf ("%s", s+1); N=Rd (); for(intI=1; i<=n;i++) {scanf ("%s", A +1); Len=strlen (A +1); Pre (); } get_next (); Solve (); for(intI=1; i<=cnt;i++) printf ("%c", S[sk[i]]); return 0;}
Usaco Feb Censoring