Concepts10
Debugging Strategies for CP
Systematic debugging beats guesswork: always re-read the statement, re-check constraints, and verify the output format before touching code.
Fast I/O and Optimization Tricks
Fast I/O reduces overhead from C and C++ stream synchronization and avoids unnecessary flushes, which can cut runtime by multiples on large inputs.
Harmonic Lemma
The Harmonic Lemma says that the values of \lfloor n/i \rfloor only change about 2\sqrt{n} times, so you can iterate those value blocks in O(\sqrt{n}) instead of O(n).
Divisor Function Sums
Summing the divisor function d(i) up to n equals counting lattice points under the hyperbola xy β€ n, which can be done in O(βn) using floor-division blocks.
Divide and Conquer DP Optimization
Divide and Conquer DP optimization speeds up DP transitions of the form dp[i][j] = min over k of dp[i-1][k] + C(k, j) when the optimal k is monotone in j.
Knuth Optimization
Knuth Optimization speeds up a class of interval dynamic programming (DP) from O(n^3) to O(n^2) by exploiting the monotonicity of optimal split points.
Interval DP
Interval DP solves problems where the optimal answer for a segment [i, j] depends on answers of its subsegments.
Wavelet Tree
A wavelet tree is a recursive data structure built over a sequenceβs alphabet that answers rank, select, and quantile (k-th smallest) queries in O(log Ο) time, where Ο is the number of distinct values.
Merge Sort Tree
A Merge Sort Tree is a segment tree where every node stores the sorted list of values in its segment.
Monotonic Deque
A monotonic deque is a double-ended queue that keeps elements in increasing or decreasing order so that the front always holds the current optimum (min or max).