随笔分类 - 算法模板
存一些常用的算法模板
摘要:// 求 n 的欧拉函数 int calPhi(int n) { int ret = n; int bd = std::sqrt(n); for (int i = 2; i <= n / i; ++i) { if (n % i == 0) { ret = ret / i * (i - 1); whi
阅读全文
摘要:// 模板矩阵 LL A[10][10] = { }; struct Matrix { void mul(LL a[10][10], LL b[10][10], LL c[10][10]) { LL tmp[10][10] {}; for (int i = 0; i < n; ++i) { for
阅读全文
摘要:constexpr int N = 100005; // ch[i][0] 代表左儿子,ch[i][1] 代表右儿子 int rt, tot, fa[N], ch[N][2], val[N], cnt[N], sz[N]; struct Splay { void maintain(int x) {
阅读全文
摘要:using ll = __int128; template <typename T> inline void rd(T &data) { T x = 0, flag = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch=='-
阅读全文