Greetings Codeforces community!
Since 2020 I've kept a repository of competitive programming templates, and I finally cleaned it up enough to share: algovault.
What it is
Most of it is my personal collection of algorithms and templates I have learned and used in programming contests over the years. The library consists of about 270 C++ templates, plus a few in Python. There are also 2000+ practice problems from various online judges linked to each problem. Here is an example from the Linear Algebra section.
Motivation
There are great libraries already. KACTL is built for ICPC team notebooks, so its code is short enough to print, and cp-algorithms, which grew out of e-maxx.ru, is the best place to learn an algorithm. There are also some good personal template collections online. My personal favorites being codelibrary by indy256 and algorithmic-library by zimpha.
However, what I wanted was slightly different. As a contestant, I prefer templates that are simple, well-tested, fast, and most importantly, easy to reuse. Essentially, a template I can paste into a solution easily during a contest without reading it first, and trust to be correct and fast.
What's different
- Verified: checked against brute force, stress tests, and planted bugs in mutation testing.
- Readable: a one-minute header and plain code with no macros.
- Reusability: every template includes
main(), which only holds self-tests and a worked example. - Drop-in: every file compiles on its own, no dependencies.
- Fast: tuned and benchmarked with documented speed tricks.
- Practiced: 2,000+ solved problems linked to their templates.
- Guarded: asserts instead of silent wrong answers.
Example: Convex Hull Trick
Usage
Using a template takes four lines:
ConvexHullTrick<long long> hull; // minimum; ConvexHullTrick<long long, true> for the maximum
hull.add_line(k, b); // slopes in non-increasing order
hull.query(x); // any x, O(log n)
hull.query_increasing(x); // non-decreasing x, O(1) amortized
Header
Every template opens with a header you can read in a minute: what it does, the complexity, the API, and the limits where it stops being correct.
Practice Problem
The last note is a recipe. 319C — Kalila and Dimna in the Logging Industry is exactly that recurrence, with dp[i] = min(dp[j] + b[j] * a[i]), so the whole solution is the template plus a loop.
Assertion
Add a slope out of order and you get a runtime error on the test that broke it, instead of a quiet wrong answer:
Assertion `k.empty() || slope <= k.back()' failed.




