Concepts158

βš™οΈAlgorithmIntermediate

Constructive Algorithm Techniques

Constructive algorithms build a valid answer directly by following a recipe, rather than searching exhaustively.

#constructive algorithm#greedy construction#invariant+12
βš™οΈAlgorithmIntermediate

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.

#time complexity#competitive programming#big-o+12
πŸ—‚οΈData StructureAdvanced

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.

#sqrt tree#range query#associative operation+11
βš™οΈAlgorithmIntermediate

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.

#modular arithmetic#modular inverse#fermats little theorem+12
βš™οΈAlgorithmIntermediate

Debugging Strategies for CP

Systematic debugging beats guesswork: always re-read the statement, re-check constraints, and verify the output format before touching code.

#competitive programming#debugging#stress testing+12
βš™οΈAlgorithmIntermediate

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.

#fast io#iostream synchronization#cin.tie+12
βš™οΈAlgorithmIntermediate

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.

#overflow prevention#long long#__int128+11
βš™οΈAlgorithmIntermediate

Small-to-Large Principle

Small-to-large means always merge the smaller container into the larger one to keep total work low.

#small-to-large#sack technique#dsu on tree+11
βš™οΈAlgorithmIntermediate

Double Counting

Double counting is the strategy of counting the same quantity in two different ways to derive an equality or an efficient algorithm.

#double counting#contribution technique#handshake lemma+12
βš™οΈAlgorithmIntermediate

Contribution Technique

The contribution technique flips perspective: compute how much each element contributes to the total, then sum these contributions.

#contribution technique#monotonic stack#sum of subarray minimums+12
βš™οΈAlgorithmIntermediate

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.

#think backwards#reverse thinking#offline queries+12
βš™οΈAlgorithmIntermediate

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.

#fix one variable#dimension reduction#two pointers+12