Which code you can rely on already existing, and which you must carry yourself.
The three that matter
| Library | Provides | Availability |
|---|---|---|
| STL | containers (vector, map, set, priority_queue), algorithms (sort, lower_bound, next_permutation) | everywhere |
| GNU PBDS | order-statistics tree, alternative hash tables | GCC only — Codeforces, AtCoder, most judges |
| ACL (AtCoder Library) | DSU, Fenwick, segment tree, lazy segment tree, max flow, MCMF, SCC, 2-SAT, NTT convolution, modint, string algorithms | AtCoder natively; elsewhere by pasting |
Between them these cover almost everything a contest needs. They are complementary rather than overlapping: the STL has no DSU and no segment tree, and ACL has no containers.
What PBDS adds
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;order_of_key(x)— how many elements are less thanfind_by_order(k)— the -th smallest
Both . That is a genuinely useful structure the STL simply lacks; see Ordered Set. gp_hash_table is also noticeably faster than unordered_map, though it needs the same custom hash to be safe from anti-hash tests.
osetis a set, not a multisetDuplicates are silently dropped. The usual workaround is to store
pair<value, uniqueIndex>and compare lexicographically.
What ACL adds
DSU, Fenwick, segment tree, lazy segment tree, max flow (Dinic), min-cost flow, SCC, 2-SAT, NTT convolution, modint, and suffix arrays / Z-algorithm. It is well tested and short. On AtCoder it is available with #include <atcoder/all>; elsewhere the source is small enough to paste the one part you need.
It is worth reading even if you never use it — the lazy segment tree and modint in particular are unusually clean designs.
The others
| Library | Verdict |
|---|---|
| KACTL (KTH) | not a compiler library — a curated set of very concise implementations, and the best single thing to read for ICPC preparation |
| Boost | occasionally useful (multiprecision, graph), rarely available, rarely needed |
| cp-algorithms | a reference site, not a library; the explanations are the value |
| Your own template | the one that actually matters — see Contest Templates |
What strong competitors actually use
STL, PBDS occasionally, ACL or their own equivalents, and a personal template of macros and tested implementations. Almost nothing external. The reason is practical: a library you did not write is a library you cannot debug at minute 90 of a contest.
The order to learn them
- STL — thoroughly, including the algorithm header
- PBDS — the ordered set, in an afternoon
- ACL — read the source of the structures you already understand
- KACTL — read for the compression tricks, paste sparingly
After that, further progress comes from algorithms and problem-solving, not from more libraries.
See also: STL Containers · Library Snippets · Tools · Ordered Set