What fits in one second

Assume roughly simple operations per second (more for tight loops, fewer with heavy constants).

ComplexityFeasible
, any
โ€“

Read the constraint, pick the row, and that is your target complexity.

Memory

TypeElements in 256 MB
bool / char
short
int / float
long long / double
bitset bits
pair<int,int>

Rules of thumb: a long long table of is 200 MB (too big); as int it is 100 MB (borderline); rolled to two rows it is 40 KB.

vector has ~24 bytes of overhead each, so vector<vector<int>> with rows costs 24 MB before any data.

Data structure operations

StructureBuildQueryUpdateSpace
Prefix sumโœ˜
Sparse tableโœ˜
Fenwick tree
Segment tree
Lazy segtree range
Sqrt decompositionโ€“
DSU
Heap top
`set`/`map`โ€”
unordered_mapโ€” avg avg
Trie
Persistent segtree new nodes
HLD + segtree

Sorting and searching

AlgorithmTimeSpaceStable
std::sort (introsort)โœ˜
stable_sortโœ”
nth_element expectedโœ˜
partial_sort (top )โœ˜
Counting sortโœ”
Radix sortโœ”
Binary searchโ€”

Graph algorithms

See Graph Complexity Cheatsheet for the full table.

AlgorithmTime
DFS / BFS
Dijkstra
Bellman-Ford
Floyd-Warshall
Kruskal
SCC
Dinic, unit
Hungarian

Useful magnitudes

QuantityValue
INT_MAX
LLONG_MAX
__int128 max
double exact integersup to
, , , ,
, , 20, 30, 60
(primes below)78 498
Max divisors below 103 680
(fits); overflows
(inverse Ackermann) for any real

Amortized vs worst case

StructureNote
vector::push_back amortized, worst
DSU amortized
Splay / link-cut tree amortized, single op
Monotonic stack total, not per operation
Segment tree beats amortized
Hash table expected, worst

Amortized bounds are fine for total-time limits; they matter only in real-time or interactive settings.

See also: Complexity Theory ยท Problem Pattern Recognition ยท Graph Cheatsheet