분류 전체보기
-
PriorityQueuePair232's competitive-programming templates. 2024. 8. 17. 02:25
template >struct PriorityQueuePair { Cmp cmp; std::priority_queue, Cmp> data; std::priority_queue, Cmp> kill; PriorityQueuePair(const Cmp& _cmp = Cmp {}) : cmp(_cmp), data(cmp), kill(cmp) { void(0); } void normalize() { while (!kill.empty()) { if (kill.top() == data.top()) { kill.pop(); data.pop(); } else { assert(cmp(kill.top(), data.top())); br..
-
Integer Divisions (ifloor, iceil, remainder)232's competitive-programming templates. 2024. 8. 15. 01:37
template auto ifloor(T t, U u) { assert(u != 0); return t / u - ((t ^ u) auto iceil(T t, U u) { assert(u != 0); return t / u + ((t ^ u) > 0 && t % u != 0);}template auto remainder(T t, U u) { assert(u != 0); if (u
-
IterativeSegmentTree232's competitive-programming templates. 2024. 8. 11. 13:23
template struct IterativeSegmentTree { int n; std::vector a; IterativeSegmentTree(int _n) : n(_n) { assert(n > 0); a.resize(2 * n); } template IterativeSegmentTree(const std::vector& v) : IterativeSegmentTree(v.size()) { for (int i = 0; i 0; --i) { a[i] = a[i void modify(int p, Types&&... args) { assert(0 >= 1; p > 0; p >>= 1) { a[p] = a[p >= 1, r >>= 1) { ..
-
PrimePowerCombination (P^E binom)232's competitive-programming templates. 2024. 8. 8. 21:16
needs Mint (because of static assertion "isPrime")overflow in constant expression "sz" will throw compile error. (i.e. P = 3, E = 40? power(3, 40) >= power(2, 31))template struct PrimePowerCombination { static_assert(P > 0 && isPrime(P) && 0 fact; constexpr PrimePowerCombination() { fact[0] = 1; for (int i = 1; i fac(int n) const { int resr = 1; int resp = 0; while (n > 0) { ..
-
extendedEuclid, crt232's competitive-programming templates. 2024. 8. 5. 19:49
using Num_t = long long;static_assert(std::is_signed_v);std::pair extendedEuclid(Num_t a, Num_t b) { Num_t ua = 1; Num_t va = 0; Num_t ub = 0; Num_t vb = 1; while (b != 0) { Num_t t = a / b; a -= t * b; ua -= t * ub; va -= t * vb; std::swap(a, b); std::swap(ua, ub); std::swap(va, vb); } if (a crt(Num_t x0, Num_t m0, Num_t x1, Num_t m1) { /* m0 * m1 ::max() / 2 */ asse..
-
LazySegmentTree232's competitive-programming templates. 2024. 8. 3. 14:14
/* * Segment should have : * Segment() * Segment(arg) * operator + * push() * clearAfterPush() * apply(args...) */template struct LazySegmentTree { int n; mutable std::vector a; void pull(int x, int l, int r) { int m = l + (r - l) / 2; a[x] = a[x + 1] + a[x + 2 * (m - l)]; } void push(int x, int l, int r) const { int m = l + (r - l) / 2; a[x].push(a[x + 1]); a[x].push(a[x + 2..
-
MergeSortTree232's competitive-programming templates. 2024. 8. 3. 12:20
template struct MergeSortTree { int n; int lg; std::vector> a; MergeSortTree(const std::vector& v) : n(int(v.size())) { lg = 0; while ((1 (n)); a[0] = v; for (int j = 0; j = (1 high) { return 0; } int res = 0; for (int lvl = 0; lvl >= 1, r >>= 1) { if (l & 1) { res += int(std::upper_bound(std::next(a[lvl].begin(), l = 0); int p = 0; for (int lvl =..