【比赛经历】
- 大概顺利满分了,就是T2的代码比较难调。
- T2能够直观地反映出GDB和输出调试结合的优越性。
【T1】Standing Out from the Herd
【题目链接】
【题解链接】
【思路要点】
- 后缀的前缀是子串,考虑使用后缀结构来解题。笔者选用的是后缀树。
- 对所有询问串建立多串的后缀树,DFS,在访问一个子树中后缀标记唯一的点时,将其父边的长度加到对应字符串的答案计数器中即可。
- 时间复杂度\(O(\sum|S|)\)。
【代码】
#include<bits/stdc++.h> using namespace std; #define MAXN 200005 #define MAXC 26 template <typename T> void read(T &x) { x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; } template <typename T> void write(T x) { if (x < 0) x = -x, putchar('-'); if (x > 9) write(x / 10); putchar(x % 10 + '0'); } template <typename T> void writeln(T x) { write(x); puts(""); } struct Suffix_Automaton { int child[MAXN][MAXC]; int father[MAXN], depth[MAXN]; int root, size, last, n; vector <int> a[MAXN]; int colour[MAXN]; bool unq[MAXN]; long long ans[MAXN]; int new_node(int dep) { depth[size] = dep; unq[size] = true; return size++; } void init() { size = 0; root = last = new_node(0); } void addcol(int pos, int col) { if (!unq[pos]) return; if (colour[pos] == 0) colour[pos] = col; else if (col != colour[pos]) unq[pos] = false; } void Extend(int ch, int col) { int np = child[last][ch]; if (np) { if (depth[np] == depth[last] + 1) { addcol(np, col); last = np; } else { int nq = new_node(depth[last] + 1); father[nq] = father[np]; father[np] = nq; memcpy(child[nq], child[np], sizeof(child[np])); for (int p = last; child[p][ch] == np; p = father[p]) child[p][ch] = nq; addcol(nq, col)