분류 전체보기
-
Hld232's competitive-programming templates. 2024. 8. 3. 01:43
struct Hld { int n; std::vector siz; std::vector top; std::vector dep; std::vector par; std::vector tin; std::vector tout; std::vector order; std::vector> adj; explicit Hld(int n) { this->n = n; siz.resize(n, 1); top.resize(n); dep.resize(n); par.resize(n); tin.resize(n); tout.resize(n); order.resize(n); adj.resize(n); } [[nodiscard]] const std::vector& ope..
-
starting position (CodeForces)232's competitive-programming templates. 2024. 8. 1. 18:47
#include using int64 = long long;void solveOne() { }int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cin.exceptions(std::ios_base::badbit | std::ios_base::failbit); int nt = 1; std::cin >> nt; for (int it = 0; it
-
Combinations232's competitive-programming templates. 2024. 8. 1. 18:37
need some kind of ModInt. (as Z)struct Combinations { int n; std::vector fact; std::vector ifact; Combinations() : n(1), fact(1, 1), ifact(1, 1) { void(0); } void ready(int m) { if (m = n; --i) { ifact[i] = (i + 1) * ifact[i + 1]; } n = new_n; } Z fac(int x) { assert(x >= 0); ready(x); return fact[x]; } Z ifac(int x) { assert(x >= 0); ready(x); return..
-
ModInt232's competitive-programming templates. 2024. 8. 1. 12:56
template constexpr T power(T a, long long b) { T res {1}; for (; b > 0; a *= a, b >>= 1) { if (b & 1) { res *= a; } } return res;}constexpr bool isPrime(long long x) { for (int i = 2; 1LL * i * i struct ModInt { int x; static constexpr int getNorm(long long x) { if (x ::max() / 2); void(0); } template constexpr explicit operator T () const { return x; } constexpr..
-
Fail function and Linear string search232's competitive-programming templates. 2024. 7. 26. 09:10
fix later (maybe to this one? http://boj.kr/cdb7471b98cf4135b27500f31f901fe2)or this? http://boj.kr/5995ff14c02b40ab973897818c78fa75template >std::vector getFail(const C& cont, Cmp&& cmp = Cmp {}) { assert(!cont.empty() && "at function \"getFail\""); int n = int(cont.size()); std::vector fail(n); for (int i = 1, j = 0; i 0 && !cmp(cont[i], cont[j])) { j = fail[j - 1]; } if (cmp(c..
-
getZ232's competitive-programming templates. 2024. 7. 26. 08:49
template >std::vector getZ(const C& cont, Cmp&& cmp = Cmp {}) { assert(!cont.empty() && "at function \"getZ\""); int n = int(cont.size()); std::vector z(n); int opt = 0; for (int i = 1; i i) { z[i] = std::min(opt + z[opt] - i, z[i - opt]); } while (i + z[i]
-
Fenwick232's competitive-programming templates. 2024. 7. 25. 23:56
template struct Fenwick { int n; std::vector a; Fenwick(int _n = 0) : n(_n) { assert(n >= 0 && "at Fenwick constructor"); a.resize(n); } template Fenwick(const std::vector& v) { n = int(v.size()); a.insert(a.end(), v.begin(), v.end()); for (int i = 0; i = 0; i = (i & (i + 1)) - 1) { res += a[i]; } return res; } [[nodiscard]] T rangeSum(int l, int r) const { ..