Codeforces 235C. Cyclical Quest 后缀自动机(二)
r[maxn]; int tn; int vis[maxn]; int READ_STR(char *str) { int i=0; char ch; while(true) { ch=getchar(); if(ch=='\n') break; str[i++]=ch; } str[i]=0; return i; } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int len=READ_STR(stmain); SAM_init(); for(int i=0;i
fa->len) cur=cur->fa; } int id=i; if(id>=n) id-=n; int to = str[id]-'a'; while(cur!=0&&cur->next[to]==0) { cur=cur->fa; if(cur!=0) nowlen=cur->len; } if(cur!=0&&cur->next[to]!=0) { cur=cur->next[to]; nowlen++; } else { cur=SAM_root; nowlen=0; } if(nowlen==n) { if(vis[cur->id]!=cas) { vis[cur->id]=cas; ans+=num[cur->id]; } } } printf("%d\n",ans); } return 0; }
?
?
?
|