Skip to content

Build Kit

Use this page when the algorithm is mostly known and the bottleneck is now:

  • implementing it cleanly
  • reopening the right snippet quickly
  • checking one invariant under pressure
  • stabilizing a suspicious solution locally

This is the repo's retrieve and execute layer.

Quick Split

  • Notebook = recall the invariant, signal, or trap
  • Template Library = retrieve the smallest reusable snippet
  • Build Kit = choose between notebook, templates, and workflow pages

What Lives Here

Need Best door
reusable contest code Template Library
short invariant/trap reminders Notebook
debug a suspicious implementation Stress testing workflow
harden a hack-sensitive or many-answer solution before trusting it Anti-Hack Workflow
interactive or simulator-style local loop Local judge workflow
many-valid-answers task and the legality contract still feels fuzzy Many-Valid-Answers / Validator-First Workflow
predicate-checked batch output or custom-judge legality Special Judge / Output Protocol Workflow
before-contest checklist Contest checklist

Exact Starter Routes

Use these when the topic is already mostly trusted and you want the shortest path back to code plus one concrete compare target.

Need Learn / check first Reuse Compare against
point updates plus prefix/range sums Fenwick hot sheet fenwick-point-prefix.cpp CVP00001
merge-only connectivity or Kruskal-style components DSU hot sheet dsu-basic.cpp C11XU
offline connectivity under an add/remove edge timeline DSU Rollback hot sheet dsu-rollback-dynamic-connectivity.cpp Dynamic Connectivity
every node needs one subtree answer from merged child containers DSU On Tree hot sheet small-to-large-subtree-merge.cpp Distinct Colors
one versioned array with point assignment and old-version range sums Persistent Data Structures hot sheet persistent-segment-tree-point-set-sum.cpp Range Queries and Copies
one branching list/sequence where merge, head, or tail create new roots while old roots stay alive Persistent Treap hot sheet persistent-treap-list-sum.cpp Persistent List
one self-hosted ordered set with split/merge by key, online rank, or k-th queries Treap / Implicit Treap hot sheet treap-key-ordered-set.cpp Salary Queries
one mutable sequence with cut/paste, insert/erase by position, or split/merge sequence surgery Treap / Implicit Treap hot sheet implicit-treap-sequence.cpp Cut and Paste
one static array with subarray k-th / count <= x / count == x queries Wavelet Tree hot sheet wavelet-tree.cpp MKTHNUM - K-th Number
one static array with many range queries where add/remove at one endpoint is cheap Mo's hot sheet mos-algorithm.cpp Powerful Array
one live multiset of integers with insert / erase / max xor queries Binary Trie hot sheet binary-trie-xor.cpp Vasiliy's Multiset
one dynamic ordered set with online rank / k-th / count-smaller queries Order Statistics Tree hot sheet pbds-ordered-set.cpp ORDERSET - Order Statistic Set
one high-fanout textbook ordered dictionary where search + insert + split-full-child are the real lesson B-Tree hot sheet b-tree-insert-search.cpp B-Tree Dictionary
one probabilistic textbook ordered dictionary where forward-pointer towers and update[] splicing are the real lesson Skiplist hot sheet skiplist-ordered-set.cpp Skiplist Dictionary
one bounded-universe integer set where predecessor / successor through prefix hashing is the real lesson X-Fast / Y-Fast hot sheet x-fast-trie.cpp X-Fast Dictionary
one live set of half-open intervals with online insert / erase / any-overlap queries Interval Tree hot sheet interval-tree-overlap-treap.cpp Reservation System
one self-adjusting ordered multiset where you explicitly want rotate / splay / parent machinery or a direct bridge into link-cut tree Splay Tree hot sheet splay-tree-ordered-set.cpp Ordinary Balanced Tree
many singleton heaps that must meld online and answer delete-min by the heap containing x Pairing / Leftist Heap hot sheet leftist-heap-meldable-pq.cpp Mergeable Heap 1
one interval partition of constant values where range assign keeps collapsing runs and range walks are acceptable ODT / Chtholly hot sheet odt-interval-set.cpp Willem, Chtholly and Seniorious
static range minimum on immutable data Sparse Table hot sheet sparse-table-rmq.cpp Static Range Minimum Queries
online range add plus range sum on one array Lazy Segment Tree hot sheet segment-tree-lazy-range-add-sum.cpp HORRIBLE
online range chmin / chmax / add / sum on one array Segment Tree Beats hot sheet segment-tree-beats.cpp Range Chmin Chmax Add Range Sum
one full mask cube where every mask needs all-submask or all-superset aggregates SOS DP hot sheet sos-dp-zeta.cpp Compatible Numbers
two full mask functions combine by xor, or one stronger boolean-cube transform family opens after plain SOS sweeps stop fitting FWHT / XOR Convolution / Subset Convolution hot sheet fwht-xor-convolution.cpp Bitwise XOR Convolution
one large boolean reachability row where packed shift-OR replaces scalar subset-sum DP Bit-Parallelism / Bitset Optimization hot sheet bitset-reachability-shift.cpp School Excursion
merge one or many congruences into one residue modulo lcm Chinese Remainder hot sheet chinese-remainder.cpp General Chinese Remainder
recover the minimum exponent from a^x ≡ b (mod m) with contest-sized square-root storage Discrete Log hot sheet discrete-log-bsgs.cpp Discrete Logarithm Mod
recover one modular square root x^2 ≡ a (mod p) under one prime modulus Modular Square Root hot sheet mod-sqrt-tonelli-shanks.cpp Sqrt Mod
find one primitive root modulo one prime once factoring p-1 is already affordable Primitive Root hot sheet primitive-root-prime.cpp Primitive Root
factor one 64-bit integer into sorted prime factors Pollard-Rho hot sheet pollard-rho-factorize.cpp Factorize
solve one linear system modulo one prime and recover any valid assignment Gaussian Elimination hot sheet gaussian-elimination-mod-prime.cpp System of Linear Equations
large nCk mod p with one small prime modulus Lucas Theorem hot sheet lucas-binomial.cpp Binomial Coefficient (Prime Mod)
gcd-1 pair counts or divisor-side inclusion-exclusion over all d <= MAX Mobius hot sheet mobius-linear-sieve.cpp Counting Coprime Pairs
one summatory divisor-function prefix sum opened through sigma = 1 * id and equal floor(n / d) quotient blocks Dirichlet prefix sums hot sheet dirichlet-convolution-sigma-sum.cpp Sum of Divisors
one huge prefix sum of phi or mu recovered implicitly on the quotient set Q_n Min_25 / Du Jiao hot sheet du-jiao-prefix-phi-mu.cpp Sum of Totient Function
one fixed-order linear recurrence or repeated linear transition under modulo Linear Recurrence hot sheet matrix-exponentiation.cpp Throwing Dice
one linear recurrence with moderate order, or enough prefix terms to recover that recurrence first Berlekamp-Massey / Kitamasa hot sheet berlekamp-massey-kitamasa.cpp K-th Term of Linearly Recurrent Sequence
subset xor span, representability, or maximum subset xor over any subset of inserted numbers XOR Basis hot sheet xor-basis.cpp XMAX - XOR Maximization
independent heaps/components under one fixed impartial move set, combined by xor of Grundy values Sprague-Grundy hot sheet sprague-grundy-subtract-set.cpp S-Nim
repeated discrete random steps with bounded sum/state and an exact probability query Probability hot sheet probability-distribution-dp.cpp Dice Probability
one truncated FPS inverse A^{-1} mod x^n under 998244353 after the NTT layer is already trusted Polynomial / FPS hot sheet fps-inv-newton.cpp Inv of Formal Power Series
one-key monotone offline sweep Offline Tricks hot sheet offline-query-skeleton.cpp Distinct Values Queries
critical roads or cities in one static undirected graph Low-Link hot sheet bridges-articulation-lowlink.cpp Necessary Roads
one static graph walk that must use every edge exactly once Eulerian hot sheet eulerian-path-cycle.cpp Mail Delivery
one binary order-n string that must contain every length-n bitstring exactly once De Bruijn Sequence hot sheet de-bruijn-sequence-binary.cpp De Bruijn Sequence
one valid boolean assignment under binary clauses Two-SAT hot sheet two-sat.cpp Giant Pizza
two rooted trees have unordered children and only shape equality matters Tree Isomorphism hot sheet tree-isomorphism-rooted.cpp Tree Isomorphism I
one rooted subtree sum with point updates Subtree Queries hot sheet euler-tour-subtree.cpp Subtree Queries
one static rooted tree query that only touches a small marked subset plus the LCAs that glue it together Virtual Tree hot sheet virtual-tree.cpp Kingdom and its Cities
bipartite maximum matching with explicit pairs Matching hot sheet hopcroft-karp.cpp School Dance
two equal-sized sides with strict full preference lists and a no-blocking-pair objective Stable Marriage hot sheet gale-shapley-stable-marriage.cpp Stable Marriage
dense square weighted assignment with one row-column pair each Hungarian hot sheet hungarian-assignment.cpp Task Assignment
non-bipartite maximum matching on one undirected graph General Matching hot sheet edmonds-blossom.cpp General Matching
plain directed max flow where you want a highest-label preflow sibling instead of the default Dinic route Push-Relabel hot sheet push-relabel-max-flow.cpp Maximum Flow
one undirected weighted graph with no designated source/sink, asking only for the cheapest disconnection cut Global Min-Cut hot sheet stoer-wagner-global-mincut.cpp Minimum Cut
one undirected weighted graph needs many pairwise min-cuts, to be compressed into one cut tree first Gomory-Hu hot sheet gomory-hu-tree.cpp MCQUERY
centroid tree structure or one O(log n) centroid-ancestor chain per node Centroid hot sheet centroid-decomposition.cpp Ciel the Commander
dynamic forest with online link / cut, vertex adds, and path sums Link-Cut Tree hot sheet link-cut-tree-path-sum.cpp Dynamic Tree Vertex Add Path Sum
dynamic forest with online link / cut, vertex adds, and subtree-side sums on one existing edge Euler Tour Tree hot sheet euler-tour-tree-subtree-sum.cpp Dynamic Tree Vertex Add Subtree Sum
exact one-pattern matching KMP kmp.cpp String Matching
one static string, longest palindrome, or all center radii Palindromes hot sheet manacher.cpp Longest Palindrome
one growing lowercase string, distinct palindromes, or longest palindromic suffix Eertree hot sheet eertree.cpp Distinct Palindromic Substrings
many lowercase patterns against one text Aho-Corasick hot sheet aho-corasick.cpp Finding Patterns
one small regex language with (), |, *, ., and exact full-string membership Regex / Finite Automata hot sheet regex-thompson-nfa.cpp Regex Membership
one optimal binary prefix-code tree from positive symbol frequencies Huffman / Data Compression hot sheet huffman-coding.cpp Huffman Coding Benchmark
one static text used as a compressed substring index for existence or earliest-occurrence queries Suffix Tree hot sheet suffix-tree.cpp Pattern Positions
exact suffix order plus LCP Suffix Array / LCP hot sheet suffix-array.cpp Repeating Substring
one bounded feasible polygon from many directed line constraints Half-Plane Intersection hot sheet half-plane-intersection.cpp Big Brother
one convex polygon built from all sums a + b of two CCW convex polygons Minkowski Sum hot sheet minkowski-sum-convex.cpp Mogohu-Rea Idol (stretch)
one global nearest Euclidean pair in one static point set Nearest Pair hot sheet closest-pair-sweep.cpp Closest Pair
static tree, point updates, path maximum HLD hot sheet hld-path-max.cpp Path Queries II
all-roots sum of distances on a tree Tree DP tree-dp-rerooting.cpp Tree Distances II
feasible circulation with lower / upper edge bounds Flow With Lower Bounds hot sheet flow-lower-bounds.cpp Reactor Cooling
fixed-value costed flow with nonnegative initial forward costs Min-Cost Flow hot sheet min-cost-flow.cpp MINCOST
decimal range counting with a small digit state Digit DP hot sheet digit-dp-skeleton.cpp Counting Numbers
small-width grid domino tilings where the frontier is an occupancy mask Broken Profile hot sheet broken-profile-domino-tiling.cpp Counting Tilings
partition DP row with monotone best split points and cheap interval cost Divide and Conquer DP hot sheet divide-and-conquer-dp.cpp Ciel and Gondolas
split-point interval DP with additive interval cost and monotone opt windows Knuth Optimization hot sheet knuth-optimization.cpp Knuth Division
online add-line / query-min on arbitrary integer x with full-domain lines CHT / Li Chao hot sheet line-container.cpp Line Add Get Min
affine DP with online line insertion on one known integer x-domain CHT / Li Chao hot sheet li-chao-tree.cpp Monster Game II
exact-K non-adjacent weighted picks where one integer penalty per pick removes the expensive count dimension Aliens Trick hot sheet aliens-trick-nonadjacent-max.cpp Red and Blue Lamps
convex piecewise-linear DP on one integer coordinate with hinge penalties or bounded argmin shifts Slope Trick hot sheet slope-trick-basic.cpp Snuketoon
one repeated buy-vs-rent decision where the future horizon is hidden and the whole lesson is competitive ratio against offline OPT Online Algorithms hot sheet ski-rental-threshold.cpp Ski Rental
one smooth differentiable loss where the whole lesson is batch gradient descent on one affine predictor Gradient Descent hot sheet gradient-descent-linear-regression-1d.cpp Linear Regression Gradient Descent Benchmark
one linearly separable binary classifier where the lesson is the perceptron update rule rather than statistical tooling Machine Learning hot sheet perceptron-linear-separable.cpp Perceptron Classification Benchmark
one Boolean oracle promised constant or balanced where the whole lesson is the Deutsch-Jozsa amplitude test in a classical simulator Quantum Algorithms hot sheet deutsch-jozsa-simulator.cpp Deutsch-Jozsa Oracle Benchmark
one additive scan benchmark where the whole lesson is the Blelloch up-sweep / down-sweep tree plus work / span reasoning Parallel Algorithms hot sheet blelloch-exclusive-scan.cpp Parallel Prefix Sum Benchmark
one small continuous LP already normalized to maximize c^T x, Ax <= b, x >= 0 Simplex hot sheet simplex-max-ax-le-b.cpp Cheese, If You Please
one explicit ground set with two independence oracles and a maximum-cardinality common independent set Matroid Intersection hot sheet matroid-intersection-oracle.cpp Pick Your Own Nim
subset-like exact search with n around 35 to 45 and one cheap merge over half summaries Meet-In-The-Middle hot sheet meet-in-the-middle-subset-sum.cpp Meet in the Middle
first smaller / greater boundary in one linear scan Monotonic Stack / Queue hot sheet monotonic-stack-nearest-smaller.cpp Nearest Smaller Values
fixed-size window minimum on a forward-only stream Monotonic Stack / Queue hot sheet monotonic-deque-min.cpp Sliding Window Minimum
same-length substring fingerprints String Hashing hot sheet rolling-hash.cpp Finding Borders
exact convolution modulo 998244353 FFT / NTT ntt.cpp Convolution
cyclic symmetry counting on one necklace under a fixed prime modulus Burnside / Pólya hot sheet burnside-cyclic-necklaces.cpp Counting Necklaces
one Bézout witness, or one inverse under composite modulus / ax + by = c Modular Arithmetic hot sheet extended-gcd-diophantine.cpp Euclid Problem

Choose The Smallest Useful Tool

Template Library

Open Template Library when:

  • you already know the family
  • you want the smallest contest-ready implementation
  • you need one fast chooser table, not a tutorial
  • you already have a topic page or note anchor and now need the smallest reusable code shape

Do not open it first if you still do not trust the topic itself.

Notebook

Open Notebook when:

  • you mostly know the idea
  • you need the main invariant, trap, or signal fast
  • you want the shortest route back to the right family

Do not use it as first exposure.

Workflows

Open a workflow page when the algorithm feels right but the solution still feels unsafe:

Build Kit Routes

If the problem feels like... Open first Then
“I know the topic, just give me the snippet” Template Library the relevant topic page only if trust is low
“I know the topic, but I forgot the invariant” Notebook the relevant template
“The code compiles, but I do not trust it” Stress testing workflow the relevant note or template
“The idea seems right, but a hack or rejudge could still break it” Anti-Hack Workflow Stress testing workflow or Local judge workflow
“This task has a judge/protocol quirk” Local judge workflow the relevant playbook or note
“I know the idea, but interactive tasks keep leaking to flush / budget / transcript discipline” Interactive Protocol Clinic 01 Local judge workflow
“This task allows many legal outputs, and I still cannot state the exact legality contract” Many-Valid-Answers / Validator-First Workflow Special Judge / Output Protocol Workflow
“The model seems right, but numeric output, tolerance, or formatting still feels brittle” Precision / Formatting Robustness Clinic 01 Foundations cheatsheet or the relevant note
“This batch task is checked by a predicate, validator, or score-aware output rule” Special Judge / Output Protocol Workflow Local judge workflow or the relevant clinic
“This is an open-ended score-based task with no single clear optimum, and I need the right operating model first” Heuristic / Marathon Intro Algorithm Engineering

Best Pairings

After This Page

  • if trust in the snippet is still low, go back to topics/
  • if you now need the next problem, go to Problem Finder
  • if you want a contest-format workflow, go to Contest Playbooks