#pragma comment( linker, "/STACK:1024000000,1024000000") #include #include #include using namespace std; #define maxnode 511111 #define sigma_size 2 struct Trie{ int ch[maxnode][sigma_size]; bool val[maxnode]; int f[maxnode]; int sz; void init(){ sz=1; memset(ch,0,sizeof(ch)); memset(val, 0, sizeof(val)); memset(f,0,sizeof(f)); } int idx(char c){ return c-'0'; } int insert(char *s){ int u = 0; for(int i = 0; s[i] ;i++){ int c = idx(s[i]); if(!ch[u][c]) ch[u][c] = sz++; u = ch[u][c]; } val[u] = 1; return u; } bool search(char *s){ int u = 0; for(int i = 0; s[i] ;i++){ int c = idx(s[i]); if(!ch[u][c]) return 0; u = ch[u][c]; } return val[u]; } void getFail(){ queue q; for(int i = 0; i 2000) join(); } else { L = buf.find(s+1) + ac.find(s+1); printf("%d\n", L); } } } return 0; }