inline Node *extend(int c, Node *p){ Node *np = new Node(p->max + 1); while (p && !p->next[c]) p->next[c] = np, p = p->fa; if (!p) { np->fa = root; } else { Node *q = p->next[c]; if (p->max + 1 == q->max) { np->fa = q; } else { Node *nq = new Node(p->max + 1, q); q->fa = np->fa = nq; while (p && p->next[c] == q) p->next[c] = nq, p = p->fa; } } return np; }
inlineintwork(char *s){ registerint res = 0; register Node *p = root; for (registerint len = 0; *s; ++s) { registerint c = *s - 'a'; while (p && !p->next[c]) p = p->fa; if (!p) p = root, len = 0; else len = std::min(p->max, len) + 1, p = p->next[c]; res = std::max(res, len); } return res; }
inlinevoidsolve(){ root = last = new Node(); staticchar s[MAXN]; scanf("%s", s); for (registerchar *c = s; *c; c++) last = extend(*c - 'a', last); scanf("%s", s); std::cout << work(s); }
inlinevoidsolve(){ init(); registerint n; read(n); staticint buf[MAXN]; for (registerint i = 0; i < n; i++) read(buf[i]); for (registerint i = 0; i < n; i++) last = extend(buf[i], last); for (registerint i = 0; i < n; i++) last = extend(buf[i], last); Node *p = root; for (registerint i = 1; i < n; i++) { print(p->next.begin()->first), print(' '); p = p->next.begin()->second; } print(p->next.begin()->first); }
inlinevoidinit(){ cur = pool; root = last = new Node(); }
inline Node *extend(int c, Node *p){ Node *np = new Node(p->max + 1); while (p && !p->next[c]) p->next[c] = np, p = p->fa; if (!p) { np->fa = root; } else { Node *q = p->next[c]; if (q->max == p->max + 1) { np->fa = q; } else { Node *nq = new Node(p->max + 1, q); q->fa = np->fa = nq; while (p && p->next[c] == q) p->next[c] = nq, p = p->fa; } } return np; }
std::vector<Node *> buc[MAXN]; Node *top[MAXN]; int tot;
inlinevoidtopoSort(constint n){ for (Node *p = pool; p != cur; p++) buc[p->max].push_back(p); for (registerint i = 0; i <= n; i++) for (registerint p = 0; p < buc[i].size(); p++) top[tot++] = buc[i][p]; }
inlineintsolve(constchar *s, constint len){ Node *p = root; registerint res = 0, max = 0; for (registerint i = 0; i < len; i++) { if (p->next[s[i] - 'a']) { max++, p = p->next[s[i] - 'a']; } else { while (p && !p->next[s[i] - 'a']) p = p->fa; if (!p) max = 0, p = root; else max = p->max + 1, p = p->next[s[i] - 'a']; } p->maxMatchLen = std::max(p->maxMatchLen, max); } for (registerint i = tot - 1; i; i--) { top[i]->minMatchLen = std::min(top[i]->minMatchLen, top[i]->maxMatchLen); top[i]->fa->maxMatchLen = std::max(top[i]->maxMatchLen, top[i]->fa->maxMatchLen); top[i]->maxMatchLen = 0, res = std::max(res, top[i]->minMatchLen); } return res; }
inlinevoidsolve(){ init(); staticchar s[MAXN]; registerint n = read(s); for (registerint i = 0; i < n; i++) last = extend(s[i] - 'a', last); topoSort(n); registerint ans = n; while (~(n = read(s))) { ans = solve(s, n); } std::cout << ans; }
inlinevoidinit(){ cur = pool; root = last = new Node(); for (registerint i = 0; i <= n; i++) buc[i].clear(); }
inline Node *extend(int c, Node *p){ Node *np = new Node(p->max + 1); while (p && !p->next[c]) p->next[c] = np, p = p->fa; if (!p) { np->fa = root; } else { Node *q = p->next[c]; if (q->max == p->max + 1) { np->fa = q; } else { Node *nq = new Node(p->max + 1, q); q->fa = np->fa = nq; while (p && p->next[c] == q) p->next[c] = nq, p = p->fa; } } return np; }
inlineintgetAns(){ registerint res = 0; Node *p = root; p->minPos = p->maxPos = 0; for (registerint i = 0; i < n; i++) p = p->next[a[i]], p->maxPos = p->minPos = i + 1; for (Node *i = pool; i != cur; i++) buc[i->max].push_back(i); for (registerint i = n; i; i--) { for (registerint j = 0; j < buc[i].size(); j++) { Node *tmp = buc[i][j]; res = std::max(res, std::min(tmp->max, tmp->maxPos - tmp->minPos - 1)); tmp->fa->minPos = std::min(tmp->fa->minPos, tmp->minPos); tmp->fa->maxPos = std::max(tmp->fa->maxPos, tmp->maxPos); } } return res < 4 ? 0 : res + 1; }
inlinevoidsolve(){ while (scanf("%d", &n), n) { for (registerint i = 0; i < n; i++) scanf("%d", a + i); n--; for (registerint i = 0; i < n; i++) a[i] = a[i + 1] - a[i] + 87; init(); for (registerint i = 0; i < n; i++) last = extend(a[i], last); std::cout << getAns() << "\n"; } } }
inlinevoidinit(){ cur = pool; root = last = new Node(); ans = 0; }
inline Node *extend(int c, Node *p){ Node *np = new Node(p->max + 1); while (p && !p->next[c]) p->next[c] = np, p = p->fa; if (!p) { np->fa = root; } else { Node *q = p->next[c]; if (q->max == p->max + 1) { np->fa = q; } else { Node *nq = new Node(p->max + 1, q); q->fa = np->fa = nq; while (p && p->next[c] == q) p->next[c] = nq, p = p->fa; } } ans += np->max - np->fa->max; return np; }
inlinevoidsolve(){ registerint n; scanf("%d", &n); for (registerint i = 0; i < n; i++) { staticchar s[MAXN]; scanf("%s", s); init(); registerint len = strlen(s); for (registerint i = 0; i < len; i++) last = extend(s[i], last); std::cout << ans << "\n"; } } }
inlinevoidinit(){ cur = pool; ans = 0; root = last = new Node(); }
inline Node *extend(int c, Node *p){ Node *np = new Node(p->max + 1); while (p && !p->next[c]) p->next[c] = np, p = p->fa; if (!p) { np->fa = root; } else { Node *q = p->next[c]; if (q->max == p->max + 1) { np->fa = q; } else { Node *nq = new Node(p->max + 1, q); q->fa = np->fa = nq; while (p && p->next[c] == q) p->next[c] = nq, p = p->fa; } } ans += np->max - np->fa->max; return np; }
inlinevoidsolve(){ registerint n; scanf("%d", &n); for (registerint i = 0; i < n; i++) { staticchar s[MAXN]; scanf("%s", s); init(); registerint len = strlen(s); for (registerint i = 0; i < len; i++) last = extend(s[i], last); std::cout << ans << "\n"; } } }
inlinevoidinit(){ cur = pool; root = last = new Node(); }
inline Node *extend(int c, Node *p){ Node *np = new Node(p->max + 1); while (p && !p->next[c]) p->next[c] = np, p = p->fa; if (!p) { np->fa = root; } else { Node *q = p->next[c]; if (q->max == p->max + 1) { np->fa = q; } else { Node *nq = new Node(p->max + 1, q); q->fa = np->fa = nq; while (p && p->next[c] == q) p->next[c] = nq, p = p->fa; } } return np; }
std::vector<Node *> buc[MAXN]; Node *top[MAXN]; int tot;
inlinevoidtopoSort(constint n){ for (Node *p = pool; p != cur; p++) buc[p->max].push_back(p); for (registerint i = 0; i <= n; i++) for (registerint p = 0; p < buc[i].size(); p++) top[tot++] = buc[i][p]; }
inlineintsolve(constchar *s, constint len){ Node *p = root; registerint res = 0, max = 0; for (registerint i = 0; i < len; i++) { if (p->next[s[i] - 'a']) { max++, p = p->next[s[i] - 'a']; } else { while (p && !p->next[s[i] - 'a']) p = p->fa; if (!p) max = 0, p = root; else max = p->max + 1, p = p->next[s[i] - 'a']; } p->maxMatchLen = std::max(p->maxMatchLen, max); } for (registerint i = tot - 1; i; i--) { top[i]->minMatchLen = std::min(top[i]->minMatchLen, top[i]->maxMatchLen); top[i]->fa->maxMatchLen = std::max(top[i]->maxMatchLen, top[i]->fa->maxMatchLen); top[i]->maxMatchLen = 0, res = std::max(res, top[i]->minMatchLen); } return res; }
inlinevoidsolve(){ init(); staticchar s[MAXN]; registerint n; read(n), n = read(s); for (registerint i = 0; i < n; i++) last = extend(s[i] - 'a', last); topoSort(n); registerint ans = n; while (~(n = read(s))) { ans = solve(s, n); } std::cout << ans; }