Algorithm template for online contests, available on
- Codeforces(pypy 3.9.10)
- Atcoder(Python 3.8.2 | pypy 3.6.9)
-
- Segment Tree
- Lazy Segment Tree (Monoid)
- ZKW Segment Tree
- Fenwick Tree
- Sparse Table
- Union Find
- Encoded Dict
- Sorted List
- Sorted Blocks
-
- Quick Power
- Binomial
- Modulo Integral
- Note: this's not faster than python big number with proper modulo operations
- Prime Table
- Exgcd and Chinese remainder theorem
-
- BFS
- Colorize bipartite graph
- Topo sort
- Shortest path
- Floyd
$O(n^3)$ - Single source
-
$O(n)$ on DAG - Dijkstra
- Spfa
-
- Floyd
- Minimal spinning tree
- Prim
- Kruskal
- MaxFlow
- Dinic
-
- 1d Hash
- KMP
- Manacher
- Longest Palindromic Prefix
- Binary Trie(Min XOR)
- Trie
-
- Point (E^d)
- quaternion
- rotate
- matrix (row major)
- polar_cmp
- find_points_in_aabb
- Segment
- intersection
- point on segment
- projection of point
- distance to point / segment
- Plane
- projection of point / segment
- Matrix
- from translate
- from rotate
- from scale
- Triangle
- normal
- area
- bounding box
- centriod
- incircle (内心)
- circumcircle (外心)
- point in triangle
- uniform sample in triangle(three kinds of algorithm)
- Polygon
- is convex or not
- signed area / area
- centriod (area based)
- triangulation by earcut algorithm
- point in polygon
- Convex Hull
- 2d quick convex hull from point cloud
- Delaunay Trianglation
- Fortune algorithm (o(n log n))
- other
- Point (E^d)
-
- BitSet
- pypy notes
s = int(1e18)-2
x = math.floor(math.sqrt(s))
while (x+1) * (x+1) <= s: x += 1
while x * x > s: x -= 1
- Append
- pop last
- get item
- set item
- get length
- get slice
- extend(k)
- copy
- insert
- pop(id)
- x in list
- del item
- iteration
- min, max, sum
- sort
- append
- appendleft
- pop
- popleft
- extend
- extendleft
- rotate
- copy
- remove
- x in s
- s-t
- s^t
- s.difference_update(t)
- s.symmetric_difference_update(t)
- s&t
- s|t
- k in d
- get item
- set item
- del item
- copy
- iteration
- heappush
- heappop
- heappushpop
- heapreplace
- merge
- heapify
- nsmallest
- nlargest
- bisect
- bisect_left
- bisect_right
- insort
- insort_left
- insort_right
- TimeComplexity - Python Wiki
- heapq — Heap queue algorithm — Python 3.10.6 documentation
- Python's heapq module
- bisect — Array bisection algorithm — Python 3.10.6 documentation
Big O notation is used to give an upper bound on the asymptotic growth
O(1)
: constantO(log n)
: logarithmicO(n)
: linearO(n log n)
: log-linearO(n^k)
: polynomial, wherek
is a constantO(c^n)
: exponential, wherec
is a constant
python gen.py > data.in && \ # generate random data
python brute.py > brute.out && \ # brute force output
python e.py > e.out && \ # algorithm output
diff e.out brute.out # diff