来吃糖
先放犯错后 be like:
![]()
1 return
// 倍增求 lca
int bfs(int x) {
  queue<int> q;
  q.push(x);
  dep[x] = 1;
  while (q.size()) {
    x = q.front(), q.pop();
    for (auto it : G[x]) {
      int y = it.first, z = it.second;
      if (dep[y]) continue;
      dep[y] = dep[x] + 1;
      d[0][y] = z;
      f[0][y] = x;
      q.push(y);
    }
  }
  rep(k, 1, 14)
    rep(x, 1, n)
      f[k][x] = f[k - 1][f[k - 1][x]], d[k][x] = max(d[k - 1][x], d[k - 1][f[k - 1][x]]);
    // here's no result
}
2 998244853
答案对 \(998244853\) 取模。
const int mod = 998244353;
3 pushdown
// 区修区查线段树
struct SGT {
  ...
  int query(int p, int l, int r, int x) {
    if (l == r) return dat(p);
    int mid = (l + r) >> 1;
    return x <= mid ? query(lc(p), l, mid, x) : query(rc(p), mid + 1, r, x);
  }
}
4 测试文件
测试文件 debug 后的代码没有放回提交文件中。
5 模数
// 加和并取模
rep(i, 2, n) {
  ans += gg * a[i] % mod - ff;
  ff = ((ff<<1) + a[i]) % mod;
  gg = (gg<<1|1) % mod;
}
6 模数Ⅱ
int a, b, c;
cin >> a >> b >> c;
cout << ((long long)a * b % mod - (long long)a * c % mod) % mod;
7 并合式发启/轻链剖分
inline void dfs(int x, int fa) {
	sz[x] = 1, L[x] = ++dfc;
	dep[L[x]] = dep[L[fa]] + 1;
	for (auto y : G[x]) {
		if (y == fa) continue;
		dfs(y, x);
		if (!son[x] || sz[son[x]] > sz[y]) son[x] = y;     // 问题出在这里。 
		sz[x] += sz[y];
	}
	R[x] = dfc;
}
将最轻的儿子的子树继承下来。
8 AC 自动机
DP 标记走不到的点一定要把相关点全都标记不能走!!!
	inline void build() {
		queue<int> q;
		if (tr[0][0]) q.push(tr[0][0]);
		if (tr[1][0]) q.push(tr[1][0]);
		while (q.size()) {
			int p = q.front(); q.pop();
			ed[p] |= ed[fail[p]];//一定要加这个
			rep(ch, 0, 1) {
				if (tr[ch][p]) fail[tr[ch][p]] = tr[ch][fail[p]], q.push(tr[ch][p]), ed[tr[ch][p]]|=ed[p];// 一定要加这个
				else tr[ch][p] = tr[ch][fail[p]];
			}
		}
#ifdef DEBUG
		cout << "trie: \n";
		rep(i, 0, tot)
			cout << i << ' ' << tr[0][i] << ", " << tr[1][i] << '\n';
#endif
	}

                
            
        
浙公网安备 33010602011771号