What fits in one second
Assume roughly simple operations per second (more for tight loops, fewer with heavy constants).
| Complexity | Feasible |
|---|---|
| , | any |
| โ | |
Read the constraint, pick the row, and that is your target complexity.
Memory
| Type | Elements 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
| Structure | Build | Query | Update | Space |
|---|---|---|---|---|
| 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
| Algorithm | Time | Space | Stable |
|---|---|---|---|
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.
| Algorithm | Time |
|---|---|
| DFS / BFS | |
| Dijkstra | |
| Bellman-Ford | |
| Floyd-Warshall | |
| Kruskal | |
| SCC | |
| Dinic | , unit |
| Hungarian |
Useful magnitudes
| Quantity | Value |
|---|---|
INT_MAX | |
LLONG_MAX | |
__int128 max | |
double exact integers | up to |
| , , | , , |
| , , | 20, 30, 60 |
| (primes below) | 78 498 |
| Max divisors below | 103 680 |
| (fits); overflows | |
| (inverse Ackermann) | for any real |
Amortized vs worst case
| Structure | Note |
|---|---|
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