随笔分类 - 模板
摘要:dsu on tree模板运用 例题以及代码: U41492 树上数颜色 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 记录详情 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) Lomsat gelral - 洛谷 | 计算机科学教育新生态 (luogu.com
阅读全文
摘要:struct Tree { int n, d = 0; //顶点,直径,树中心 //自顶向下u到其叶子结点最远距离d1,次长距离d2(与最长路径无公共边) //p1,p2表示结点u向下更新时是由哪个结点更新来的 //up表示结点u向上到祖宗结点的最远距离 vector<int> d1, d2, p1
阅读全文
摘要:自然溢出哈希 struct Hash { using u64 = unsigned long long; u64 base = 13331; vector<u64> pow, hash; Hash(string &s) { s = " " + s; int N = s.size(); pow.res
阅读全文
摘要:#define L(x) (1 << (x)) const double PI = acos(-1.0); const int N = 1e7 + 10; double ax[N], ay[N], bx[N], by[N]; char sa[N / 2], sb[N / 2]; int sum[N]
阅读全文
摘要:jiangly的板子 // 取模机 // using i64 = long long; template<class T> constexpr T power(T a, i64 b) { T res {1}; for (; b; b /= 2, a *= a) { if (b % 2) { res
阅读全文
摘要:struct SCC { int top = 0, cntscc = 0, dfncnt = 0, n; vector<int> dfn, low, stk, instk; vector<int> sccnum, sccid; vector<vector<int>> g, scc; SCC(int
阅读全文
摘要:取分块大小 \(n^\frac{2}{3}\) 最优。 例题:数颜色 #include<bits/stdc++.h> using namespace std; using i64 = long long; const int N = 1e6 + 5; int cnt[N], a[N]; struct
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; using i64 = long long; const int N = 1e6 + 5; int cnt[N], a[N]; struct query { int l, r, id; }; int main(
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; using i64 = long long; const int N = 1e6 + 5; //本模板是从左往右扫的,从下往上扫同理 #define ls (rt<<1) #define rs (rt<<1|1
阅读全文
摘要:struct BigInteger { static const int BASE = 100000000; static const int WIDTH = 8; vector<int> s; bool sign; BigInteger(long long num = 0) { *this = n
阅读全文
摘要:Exgcd 模板 pair<int, int> exgcd(int a, int b) { if (b == 0)return make_pair(1, 0); auto [x, y] = exgcd(b, a % b); pair<int, int> ans = make_pair(y, x -
阅读全文
摘要:判断负环模板 Bellman_ford \(\mathcal{O}(nm)\) struct Bellman_ford { using i64 = long long; using PII = pair<i64, i64>; int n; vector<i64> dis; vector<array<
阅读全文
摘要:struct DIJ { using i64 = long long; using PII = pair<i64, i64>; vector<i64> dis, path, node; vector<vector<array<int, 3>>> G; int n; DIJ() {} DIJ(int
阅读全文
摘要:struct Node { int data; Node* left; Node* right; Node* newNode(int v) { Node* node = new Node; node->data = v; node->right = node->left = NULL; return
阅读全文
摘要:KMP模板 struct Kmp { vector<int> next; void getNext(string p) { int j = 0, k = -1, n = p.size(); next.resize(n + 1); next[0] = -1; while (j < n) { if (k
阅读全文
摘要:单点修改区间查最值-树状数组模板 #include <bits/stdc++.h> #define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; using i64 = long long; typedef pair<i64, i64>
阅读全文
摘要:struct Two_D_Discrete { int n, tot1 = 1, tot2 = 1; vector<vector<int>> mp; vector<int> x, y, nx, ny; vector<pair<i64, i64>> a; vector<PII> New; Two_D_
阅读全文
摘要:单点修改,区间查询/区间修改,单点查询 template<typename T> struct BIT { int n; vector<T> w; BIT() {} BIT(int n) { this->n = n; w.resize(n + 1); } void update(int x, int
阅读全文
摘要:例题:P3366 【模板】最小生成树 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) Kruskal #include <bits/stdc++.h> #define debug(a) cout<<#a<<"="<<a<<'\n'; using namespace std; usi
阅读全文
摘要:例题素数密度 template<typename T> struct segment_sieve { vector<bool> is_prime, is_prime_small; vector<T> prime; segment_sieve() { is_prime.resize(1000010);
阅读全文

浙公网安备 33010602011771号