随笔分类 - YBT题解
摘要:A.线性筛素数 先记下埃式筛 for (int i = 2; i <= n; ++i) { if (vis[i]) continue; p[++top] = i; for (int j = 2; i * j <= n; ++i) vis[i * j] = 1; } 看起来就很容易理解 时间复杂度 \
阅读全文
摘要:### A.序列的第k个数   { int n, k; sc
阅读全文
摘要:A.种植方案 范围看起来很状压 放不放奶牛看起来也很状压 那我们就状压 首先判左右不同时有 那就判它左/右移一位和原来与起来为 然后判上下不同时有 那就判上一行和当前行与起来为 然后要判当前放置方案和地形是否符合 那就判它和地形与起来不为 有个常数上的小优化 就是
阅读全文
摘要:A.采药问题 背包板子题 点击查看代码 #include <bits/stdc++.h> using namespace std; const int N = 1001; int w[N], c[N]; int mem[N][N]; int n, t; int dfs(int x, i
阅读全文
摘要:A.查找编号 一眼二分 但是也可以拿倍增做 我们维护这个点往后 格位置的元素大小 然后从大到小枚举 的次数 如果往后 格的元素小于要查的 就跳 否则不跳 代码我写的二分就不放了 B.开车旅行 说句题外话 如果你是从 LCA 那章一路刷下来的 你会经历紫题三
阅读全文
摘要:A.树上距离 板子 详见P3379 最近公共祖先模板 点击查看代码 #include <bits/stdc++.h> using namespace std; const int N = 1e5 + 0721; int head[N], nxt[N], to[N], len[N], cnt; int
阅读全文
摘要:A.求区间和 板子 详见线段树学习笔记 点击查看代码 #include <bits/stdc++.h> #define int long long #define ls (k << 1) #define rs (k << 1 | 1) #define mid ((l + r) >> 1) using
阅读全文
摘要:A.数列区间 板子 详见P3865 ST表 点击查看代码 #include <bits/stdc++.h> using namespace std; int n, m; const int N = 1e5 + 0721; int a[N], rmq[N][21], Log[N]; int main(
阅读全文
摘要:A.单点修改区间查询 板子 点击查看代码 #include <bits/stdc++.h> #define int long long using namespace std; const int N = 1e6 + 0721; int c[N]; int n, m; int lowbit(int
阅读全文
摘要:A.合并果子 很容易想到 先合并的果子 对答案的贡献明显更多 所以我们每次合并都取最小的两堆进行合并 因为每次变动的元素数量很少 选择堆排 点击查看代码 #include <bits/stdc++.h> #define ll long long using namespace std; ll ans
阅读全文
摘要:A.有向图缩点 板子 讲解有时间补 咕 点击查看代码 #include <bits/stdc++.h> using namespace std; const int N = 200721; int head[N], nxt[N], to[N], v[N], cnt; int sccnum[N], s
阅读全文
摘要:A.单源最短路径 板子 没啥好说的 点击查看代码 #include <bits/stdc++.h> using namespace std; const int N = 2e5 + 0721; int head[N], to[N], nxt[N], len[N], cnt; bool vis[N];
阅读全文
摘要:前注:本文涉及的所有求最小生成树的算法均为 A.繁忙都市 要求联通并且边最少 个节点联通最少要 条边 那不就是棵树嘛 然后跑最小生成树就行了 点击查看代码 #include <bits/stdc++.h> using namespace std
阅读全文
摘要:A.并查集 他都说模板了!!! 那就是板子 点击查看代码 #include <bits/stdc++.h> using namespace std; const int N = 1e4 + 0721; int fa[N]; int n, m; int find(int x) { if (x == f
阅读全文
摘要:A.单词查询 AC自动机板子 大致讲一下AC自动机是什么东西 首先我们把匹配的若干个串插到 树里 然后把要匹配的串放到树里跑 显然 我们是不能暴力跑的 所以要构建失配指针 假如说我这个节点是父节点连了条字母为 的边 那么这个节点的失配指针就要指到它父亲的失配指针指向的节
阅读全文
摘要:A.前缀统计 字典树 顾名思义就是做一个类似于字典的树 根节点往下连边 每条边代表一个字母 对于插入操作 我们从根节点出发往下走 如果有对应的字母边 就继续走到对应的儿子节点 如果没有 就新建一个节点 查询同理 按字母边往下走即可 点击查看代码 #include <bits/stdc++.h> us
阅读全文
摘要:A.子串查找 板子 详见KMP学习笔记 点击查看代码 #include <bits/stdc++.h> using namespace std; const int N = 1e6 + 0721; char s1[N], s2[N]; int kmp[N]; int ans; int main()
阅读全文