chenfy27的刷题记录

导航

2024年10月16日 #

模板-质因子分解

摘要: 版本1:求n的所有质因子,时间复杂度O(sqrt(n))。 // 例如:12=2*2*3,那么 // factor(12, 1) => {2,3} // factor(12, 0) => {2,2,3} std::vector<int> factor(int n, int removeDup) { 阅读全文

posted @ 2024-10-16 12:48 chenfy27 阅读(49) 评论(0) 推荐(0)

模板-并查集DSU

摘要: 版本1:路径压缩。 struct DSU { std::vector<int> fa; void init(int n) { fa.resize(n + 1); std::iota(fa.begin(), fa.end(), 0); } int leader(int x) { while (x != 阅读全文

posted @ 2024-10-16 12:40 chenfy27 阅读(48) 评论(0) 推荐(0)

模板-组合数comb

摘要: 使用前需要初始化,执行一次comb.init(n),n为C(n,m)中最大的n。初始化时间复杂度为O(n),后续每次求comb(n,m)时间复杂度为O(1)。 std::vector<mint> fac, ifac; struct Comb { void init(int n) { fac.assi 阅读全文

posted @ 2024-10-16 12:37 chenfy27 阅读(64) 评论(0) 推荐(0)

模板-自动取模整型mint

摘要: 输入为int64类型,底层用int64表示,每次运算后自动取模。 template<int MOD> struct MInt { i64 x; int norm(i64 u) const {u%=MOD; if(u<0) u+=MOD; return u;} MInt(i64 v=0):x(norm 阅读全文

posted @ 2024-10-16 12:33 chenfy27 阅读(38) 评论(0) 推荐(0)