For the name-string-built AC automata. The numbers are too big to write a treap>_<.
And then everyone was directly violent and ran names on the AC automata. Each match to a node is updated with the answer along the fail chain.
Presumably it would have been a random card. So there is a small optimization is that, along the fail to jump if you have already walked before you do not go. The concrete implementation is better than bool with Int. (Lazy initialization series)
At first ... And then write an output optimization, and then get rid of something unnecessary. 2333
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <cstdlib>5 using namespacestd;6 Const intmaxn=100233;7 structzs{8 intToo,pre;9 };Ten intLc[maxn],rc[maxn],rnd[maxn],num[maxn],pre[maxn],tot;//pre[i] node I recently by who hand-picked One intRT[MAXN],S[MAXN],FAIL[MAXN],SIZE[MAXN]; A intDL[MAXN],DL[MAXN]; - intlen[2][MAXN]; - the intNamlast[maxn],namtot;zs NAME[MAXN]; - intSurlast[maxn],surtot;zs SURE[MAXN]; - intVislast[maxn],vistot;zs VISE[MAXN];//correct reading method of variable name >_<:vis_last,vis_tot,vis_e - intcalled[20023],call[maxn],endpos[50023]; + inti,j,n,m,k; - + AInlinevoidLturn (int&x,intR) { atrc[x]=lc[r],lc[r]=x,x=R; - } -InlinevoidRturn (int&x,intL) { -lc[x]=rc[l],rc[l]=x,x=L; - } -InlinevoidInsint&x,intv) { in if(!x) {X=++tot,rnd[x]=rand () + (x<<1), Num[x]=v;return;} - if(v<Num[x]) { to ins (lc[x],v); + if(rnd[lc[x]]<rnd[x]) Rturn (x,lc[x]); -}Else if(v>Num[x]) { the ins (rc[x],v); * if(rnd[rc[x]]<rnd[x]) Lturn (x,rc[x]); $}Else return;Panax Notoginseng } - voidGetch (intXintVint&son) { the while(X&&NUM[X]!=V) x=v<num[x]?Lc[x]:rc[x]; +son=x; A } theInlinevoidInsertintLenintID) { +Registerinti,now=0, TMP; - for(i=1; i<=len;i++){ $ Getch (rt[now],s[i],tmp); $ if(TMP) now=tmp; - ElseINS (Rt[now],s[i]), now=tot; - } thesize[endpos[id]=now]++; - }WuyiInlinevoidGetfail () { theRegisterintI,now,tmp,l=0, r=1, l,r,now;dl[1]=0; - while(l<R) { Wunow=dl[++l]; - if(Rt[now]) dl[++r]=Rt[now]; About for(l=0, r=rt[now]!=0, Dl[r]=rt[now]; l<R;) { $now=dl[++L]; - if(!now) fail[now]=0;Else{ -I=Fail[now],getch (rt[i],num[now],tmp); - while(i&&!tmp) i=Fail[i],getch (rt[i],num[now],tmp); Afail[now]=tmp; + } the if(Lc[now]) dl[++r]=dl[++r]=Lc[now]; - if(Rc[now]) dl[++r]=dl[++r]=Rc[now]; $ } the } the } the the - intRaCharRx; inInlineintRead () { theRx=getchar (), ra=0; the while(rx<'0'|| Rx>'9') rx=GetChar (); About while(rx>='0'&&rx<='9') ra*=Ten, ra+=rx- -, Rx=getchar ();returnRA; the } the Charss[ A];intLlen; theInlinevoidOutxintx) { + if(!x) {Putchar ('0');return;} - while(x) ss[++llen]=x%Ten, x/=Ten; the while(Llen) Putchar (ss[llen--]+ -);Bayi } the the - intMain () { -Registerinti,j,len,k,now,to; theN=read (), m=read (); the for(i=1; i<=n;i++){ the intlen=read (); the for(j=1; j<=len;j++) Name[++namtot].too=read (), name[namtot].pre=namlast[i],namlast[i]=Namtot; -len=read (); the for(j=1; j<=len;j++) Sure[++surtot].too=read (), sure[surtot].pre=surlast[i],surlast[i]=Surtot; the } the for(i=1; I<=m;insert (j,i), i++)94 for(Len=j=read (); len;len--) s[len]=read (); the Getfail (); the for(i=1; i<=n;i++){ the for(j=namlast[i],now=0; j;j=name[j].pre) {98 for(Getch (rt[now],name[j].too,to); now&&!to;now=Fail[now],getch (rt[now],name[j].too,to)); About for(K=now=to;k&&pre[k]<i;pre[k]=i,k=fail[k])if(Size[k]) -called[i]+=size[k],call[k]++;101 }102 103 for(j=surlast[i],now=0; j;j=sure[j].pre) {104 for(Getch (rt[now],sure[j].too,to); now&&!to;now=Fail[now],getch (rt[now],sure[j].too,to)); the for(K=now=to;k&&pre[k]<i;pre[k]=i,k=fail[k])if(Size[k])106called[i]+=size[k],call[k]++;107 }108 }109 for(i=1; i<=m;i++) Outx (Call[endpos[i]), Putchar ('\ n'); the for(i=1; i<=n;i++){111OUTX (Called[i]);if(i<n) Putchar (' '); the }113 return 0; the}
View Code
Concrete implementation is a bit annoying ... The main is to save the name. I'm a jerk who wrote a chain of forward stars, and then directly handled everything in reverse. Tat
In fact, the complexity is still a bit of metaphysics ... Theoretically, you can get a card? But not that (du) (Liu) Good (LAI) card (le) = =
[bzoj2754] [SCOI2012] The name on the Meow planet