Learn Competitive Programming: Free Competitive Programming Tutorial in 24 Lessons
Learn Competitive Programming free: 24 lessons in 12 modules, from first programs to interview questions, with exercises judged on Clang 18 · C++20 and a certificate.
- Language: Competitive Programming
- Runtime: Clang 18 · C++20
- Modules: 12
- Lessons: 24
- Reading time: about 13 hours
- Cost: Free on every plan, with a certificate
The contest toolkit in C++: complexity budgets, prefix sums, bit tricks, binary search on the answer, greedy proofs, number theory, DSU, shortest paths, segment trees, DP optimisations and string algorithms — judged at the limits.
Syllabus
Module 1: Fast I/O and complexity budgets
The contest template, fast input and output, long long by default, and reading the constraints to know which complexity will pass in one second.
Module 2: Prefix sums and difference arrays
Answer any range sum in O(1) after one O(n) pass, and apply many range updates with two writes each — the two halves of one idea.
Module 3: Bit manipulation
Set, clear, toggle and test bits, XOR's cancelling pairs, popcount, and every subset of n ≤ 20 items as a mask from 0 to 2ⁿ − 1.
Module 4: Binary search on the answer
Minimise the maximum, maximise the minimum: write a yes/no check for one guess, prove it monotone, and let about sixty halvings find the best value — with long long ranges and checks that cannot overflow.
Module 5: Greedy algorithms and exchange proofs
Sort, sweep, commit: activity selection by earliest finish, event sweeps for platforms and rooms, ordering by an exchange argument — and the counterexamples that send a problem to DP instead.
Module 6: Number theory: sieve, modular arithmetic, nCr
The Sieve of Eratosthenes with prefix counts, exponentiation by squaring, inverses by Fermat's little theorem, nCr mod 1e9+7 from factorial tables, and __int128 for moduli near 10^18.
Module 7: Disjoint set union (DSU)
Union-find in twelve lines: a parent array, path compression and union by size — components, cycle detection and Kruskal's minimum spanning tree at contest limits.
Module 8: Shortest paths: BFS, 0-1 BFS, Dijkstra
Choose the algorithm from the weights — BFS for equal edges, 0-1 BFS with a deque, Dijkstra with a priority_queue and lazy deletion — and write it right under a clock.
Module 9: Topological sort and DAGs
Kahn's algorithm with in-degrees, a min-heap for the smallest order, the cycle test by count, and dynamic programming in topological order: longest paths, path counts, semesters.
Module 10: Segment trees and Fenwick trees
Range queries with updates in O(log n): a segment tree for sums and minimums, a Fenwick tree in ten lines with i & -i, and counting inversions by value.
Module 11: DP optimisations
Make the transition cheap: prefix sums over the previous row, a monotonic deque for a sliding-window maximum, and bitmask DP over subsets of up to twenty items.
Module 12: String algorithms: KMP, Z and hashing
Linear-time matching with the KMP prefix function and the Z-function, borders and periods, and O(1) substring comparison with a double rolling hash.