Concepts158
Constructive Algorithm Techniques
Constructive algorithms build a valid answer directly by following a recipe, rather than searching exhaustively.
Complexity Analysis Quick Reference
Use an operation budget of about 10^8 simple operations per second on typical online judges; always multiply by the time limit and number of test files if known.
Sqrt Tree
A sqrt tree is a layered block-decomposition data structure that answers range queries in O(1) time after O(n \log \log n) preprocessing.
Modular Arithmetic Pitfalls
Modular arithmetic is about working with remainders, but programming languages often return negative remainders, so always normalize with (a % MOD + MOD) % MOD.
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.
Overflow Prevention Techniques
Integer overflow happens when a computed value exceeds the range of its type; in C++ this silently wraps for unsigned and is undefined for signed, so prevention is crucial.
Small-to-Large Principle
Small-to-large means always merge the smaller container into the larger one to keep total work low.
Double Counting
Double counting is the strategy of counting the same quantity in two different ways to derive an equality or an efficient algorithm.
Contribution Technique
The contribution technique flips perspective: compute how much each element contributes to the total, then sum these contributions.
Think Backwards (Reverse Thinking)
Think Backwards is a problemβsolving pattern where you reverse time or direction so hard deletions become easy insertions and the final state becomes the starting point.
Fix One Variable Technique
The Fix One Variable technique reduces multi-variable search problems by enumerating one variable explicitly and optimizing over the others with structure.