CP Snippets
About
A collection of CPP Snippets to aid in competetive programming.
This site was auto generated with the help of marked.
The old version of site is available here.
This site is also available in the form of a PDF book for your convenience, you can download it from here.
curl -L "https://raw.githubusercontent.com/theSoberSobber/CP-Snippets/main/snippets.json" > snippets.json
Index -
- BIT-general : easy BIT general with range updates by diff array too
- DSU : DSU
- [ExtendedGcdDiophantine](https://thesobersobber.github.io/CP-Snippets/Extended GCD Diophantine, All Solution, Any Solution) : Diophantine any and all soln
- General-Hash : General Hash functions that returns two hashes, takes in 0 indexed arr or string, allows hash query on range, beware that this uses the decreasing power convention
- [Inline-break](https://thesobersobber.github.io/CP-Snippets/Inline Break) : Inline Break by defining break to a function that basically breaks but returns value and hence can be used as a expression with comma operator
- LCA-RMQ : LCA using Range Min Query(Sparse) on ETT (Reference)
- PrefSum2D : 2D Prefix Sum
- Segtree-General : General segree, needs node struct (with members def and epsilon(default) for all of them) and operation lambda (merge)
- Simpler-Segtree : Init with an array simply using the build fn, customize operation and epslion in the struct itself, supports point updates and range queries
- Sparse-General : General Implementation of Sparse table with the template structure
- [Weird_Lazy_Segtree](https://thesobersobber.github.io/CP-Snippets/Lazy Segtree) : A lazy segtree taken from a abc340 E mridulahi submission, it's supposed to be able to do range updates and point queries
- [Xor-Of-First-N-Natural-Numbers](https://thesobersobber.github.io/CP-Snippets/Xor of first N Natural Numbers) : based on the fact that if n%4==3 then xor till n from 1 is 0
- arr-inp : arr-inp
- arr-pref : arr-pref
- bfs-dist : bfs that measures levels/dist
- binpow : binpow
- binsearch : binsearch
- bp-small : bp-small
- bp : bp
- clock_for_TL : clock
- combi-mint : combi template with mint
- combi-struct : combi-struct
- combination-non-mod : combination-non-mod
- combination-small : combination-small
- combination : combination
- crt : crt
- cute-lcm : [a,b,c]=abc(a,b,c)/(a,b)(b,c)(c,a), where []=lcm adn ()=gcd or [a,b,c]=abc/gcd(ab,bc,ca)
- derangments : derangments
- dfs-full : dfs with lots of stuff implemented
- dfs : weird ass dfs
- diophantine : linear diophantine
- dsu-rr : dsu-rr
- easy_seive : easy_seive
- euclid : euclid
- explanation_binsearch : explanation_binsearch
- fac : fac
- factorization : factorization
- fenwick : binary indexed tree
- file_io : for coding competetions
- freq-map : freq-map
- gr-inp-Fwt : graph input weight
- gr-inp : graph input
- highest_exponent : power_in_fac
- interactive : essential measures for interactive problems
- ip-overloads : I/O Overloads that I don't use
- kadane : max subarray sum O(n)
- kahn's algo : toposort using bfs (kahn's algo)
- kosaraju : kosaraju
- kruskal : kruskal
- lambda_function : lambda_function
- lca-isAncestor : lca that uses isAncestor instead of level jumping, sets a level upper limit of 25 itself since 2^25 is bigger than any N give anyways
- lca : LCA path satisfying some condition
- log : log
- matrix : matrix
- mint : modular integer
- modpow : modpow
- pbds : pbds
- pq : pq
- prime-related-stuff : implements prime fac, fac list and is_prime in both space optimized and time optimized ways
- re-write : a bunch of re and write functions based on template meta programming heklpful in cp.
- recur-binsearch : recursive binary search implementation to make intution easier ig
- recur-modpow : recur-modpow
- rng : rng
- rr-segtree : best segtree
- segtree : sextree
- seive : seive
- [splay-tree-rr-sir](https://thesobersobber.github.io/CP-Snippets/Splay Tree) : used here by rr sir, I have no idea how to use it or what it's used in mostly, RR Sir ABC F Submission
- tokenizer : tokenizer that has no use
- totient-seive : totient-seive
- totient : totient
- trie : trie
- troll : troll
- two-sat (kosaraju) : two-sat (kosaraju)
- variadic : variadic lambdas with 1 and 2 arguments
- xor-basis : xor-basis