Skip to content

About

Algorithm Template.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Tangzy's Algorithm Template Library

184 C++ algorithm templates for competitive programming. Jiangly-style (struct + template, PascalCase, K&R braces), 0-indexed, [l, r) intervals.

Quick Start

// Copy Header first, then paste templates below:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using f32 = double;        using u32 = uint32_t;
using i64 = int64_t;       using u64 = uint64_t;
using f64 = double;        using f80 = long double;
using f128 = __float128;
using i128 = __int128_t;   using u128 = __uint128_t;
using namespace std;
// Paste template here ↓

Directory Structure

Tangzy_template/
├── Header                 # Common header
├── 01_Utilities/          # 17 templates
├── 02_Data_Structures/    # 54 templates
├── 03_Math/               # 41 templates
├── 04_Graph/              # 45 templates
├── 05_Strings/            # 10 templates
├── 06_Geometry/           #  7 templates
├── 07_DP/                 # 10 templates
└── README.md

Conventions

  • 0-indexed everywhere
  • [l, r) left-closed right-open for all range queries/updates
  • TODO comments mark framework/skeleton code that needs customization

Categories

01_Utilities (17)

I/O (int128/float128/fast), hash & pb_ds, PBDS ordered set/map, random & debug, discretization, subset enumeration/Gosper's Hack, Cantor expansion, common utilities (ceilDiv/floorDiv/sqrt), radix sort, game theory (SG/Nim/...), 0-1 fraction planning, meet-in-the-middle, simulated annealing, enumeration (permutation/combination), group cycle, diamond prefix sum.

02_Data_Structures (54)

DSU×5 (plain/weighted/rollback/removable/complete), Fenwick×4 (1D/1D-range/2D/2D-range), SegmentTree×9 (point/lazy/ZKW/dynamic/persistent/0-1/merge-split/Li Chao/Beats), SparseTable×3 (1D/2D/complete), Disjoint Sparse Table, Trie×3 (plain/01-v1/01-v2), Monotonic Stack+Queue, 2D Sliding Window, Queue with Aggregation, Cartesian Tree, Bitset, Leftist Heap, Sqrt Decomposition, Mo×4 (standard/rollback/with-update/on-tree), Mo Twice Offline, CDQ Divide & Conquer, Segment Tree D&C, Treap×2 (rotating/FHQ), Splay, Link Cut Tree, Lazy Heap, Double Heap (median), Sliding Window Top-K, KD-Tree, Dancing Links (DLX), ODT, Sweep Line, Block List, SegTree of SparseTable.

03_Math (41)

Number Theory×4 (sieve/Miller-Rabin+Pollard-Rho/divisors/factorization), ModInt×3 (basic/dynamic/Montgomery), Misc NT (inverse linear+offline/fastGCD+exGCD/Euler phi+extended Euler), Combinatorics, NTT + Poly Family (inv/ln/exp/sqrt/pow/div), Matrix, Gauss Elimination, XOR Basis, FWT, Subset Convolution, Mobius Inversion, Primitive Root+BSGS+exBSGS, Lucas+exLucas, CRT+exCRT, Division Block, Catalan, Euclid-like, Adaptive Simpson, Lagrange Interpolation, Stirling+Bell+Motzkin+Narayana+Euler, Min25 Sieve, Du Jiao Sieve, Simplex, SOS DP / Dirichlet, Pell Equation, N-th Residue, Quadratic Residue, Berlekamp-Massey+Kitamasa.

04_Graph (45)

Graph class (Dijkstra/SPFA/Johnson), LCA (binary lifting), SCC (Tarjan), EBCC & v-BCC (block-cut tree), 2-SAT, HLD, Long Chain Decomposition, MaxFlow×2 (Dinic/ISAP), MinCostMaxFlow, Bounded Flow, Gomory-Hu Tree, Stoer-Wagner (global min cut), Hopcroft-Karp, KM (Hungarian), Blossom (general matching), Eulerian Graph, Segment Tree Graph, Topological Sort, Kruskal, Second MST, Chu-Liu (arborescence), Bipartite Check, Articulation Points, 0-1 BFS, Minimum Cycle, Lexicographically Smallest Shortest Path, Pseudo Forest, Parallel Binary Search, 3/4-Cycle Counting, Tree: Diameter/Centroid, DSU on Tree, Centroid Decomposition, Virtual Tree, Prufer (bidirectional), Tree Hash, Tree Difference, Tree Block, Dominator Tree, Steiner Tree, Bron-Kerbosch (max clique), Difference Constraints, Cactus.

05_Strings (10)

KMP, Z-Function, Border Tree (fail tree), Manacher, String Hash, Aho-Corasick, Suffix Array (doubling), Suffix Automaton (SAM), Palindrome Automaton (PAM), Minimal Rotation (Duval/Lyndon).

06_Geometry (7)

Point2D, Line & Segment, Polygon, Convex Hull (Andrew + Rotating Calipers + Minkowski Sum), Half-Plane Intersection, Circle (intersections + min enclosing circle), Misc (closest pair, polar sort, segment distance).

07_DP (10)

Knapsack (0/1/complete/multiple monotonic queue), Digit DP, Convex Hull Trick, Quadrangle Inequality, WQS Binary Search, Tree DP (knap/reroot), Bitmask DP (TSP/subset), Plug DP (Hamiltonian circuit), LIS/LCS, Dynamic DP (HLD+matrix).

About

Algorithm Template.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages