diff --git a/content/4_Silver/DFS.mdx b/content/4_Silver/DFS.mdx index 90d857b..0b64c39 100644 --- a/content/4_Silver/DFS.mdx +++ b/content/4_Silver/DFS.mdx @@ -25,6 +25,7 @@ export const metadata = { new Problem("CSES", "Tree Distances II", "1133", "Normal", false, ["Tree", "DFS"]), new Problem("CF", "Wizard's Tour", "contest/860/problem/D", "Normal", false, ["Tree", "DFS"]), new Problem("POI", "Hotels", "https://szkopul.edu.pl/problemset/problem/gDw3iFkeVm7ZA3j_16-XR7jI/site/?key=statement", "Normal", false, ["Tree", "DFS"]), + new Problem("HE", "Birthday Gifts", "https://www.hackerearth.com/practice/math/combinatorics/inclusion-exclusion/practice-problems/algorithm/mancunian-and-birthday-gifts-d44faa15/description/", "Normal", false, ["Tree", "PIE"], ""), new Problem("CSA", "Tree Construction", "contest/860/problem/D", "Hard", false, ["Tree", "DFS"], "several cases"), ], general: [ @@ -51,12 +52,6 @@ export const metadata = { - - -Quite frequent at the Silver level. - - - ## Tutorial - Recommended: diff --git a/content/5_Gold/Cyc.mdx b/content/5_Gold/Cyc.mdx index 62b9e15..f4bce87 100644 --- a/content/5_Gold/Cyc.mdx +++ b/content/5_Gold/Cyc.mdx @@ -3,8 +3,7 @@ id: cyc title: Cycle Detection author: Siyong Huang prerequisites: - - Silver - Functional Graphs - - Gold - Breadth First Search + - Gold - Topological Sort description: A simple cycle is a non-empty path of distinct edges that start and end at the same vertex such that no vertex appears more than once. Describes how to detect cycles in both directed and undirected graphs. frequency: 0 --- @@ -32,13 +31,17 @@ export const metadata = { -BFS-Cycle? + + +An algorithm known as **BFS-Cycle** returns an integer that is at most one more than the length of the shortest cycle in $O(N^2)$ time; see page 4 [here](https://people.csail.mit.edu/virgi/6.890/lecture9.pdf) for details. + + ## Directed Graphs -The same general idea is implemented below to find any cycle in a directed graph (if one exists). +The same general idea is implemented below to find any cycle in a directed graph (if one exists). Note that this is almost identical to the DFS algorithm for topological sorting. ```cpp //UNTESTED diff --git a/content/5_Gold/DP.mdx b/content/5_Gold/DP.mdx index 0ad2830..c1c7702 100644 --- a/content/5_Gold/DP.mdx +++ b/content/5_Gold/DP.mdx @@ -62,11 +62,11 @@ Usually, at least one problem from every gold division contest involves some sor The following tutorials serve as an introduction into the mindset of DP. - Great introduction that covers most classical problems + great introduction that covers most classical problems great for all skill levels examples with nonclassical problems also covers many classical problems - + starts with DAGs, which are covered in "Topological Sort" Practice makes perfect. Start by doing some classical problems (try at least one of each), as these are **must know** DP problems. Each topic starts with direct applications of the classical problems, and then some interesting variations and USACO problems which utilize the ideas. Solutions for most problems (excluding USACO) can be found on Chapter 7 of CPH. diff --git a/content/5_Gold/DSU.mdx b/content/5_Gold/DSU.mdx index 1ead780..8695c68 100644 --- a/content/5_Gold/DSU.mdx +++ b/content/5_Gold/DSU.mdx @@ -48,6 +48,8 @@ export const metadata = { +Note: You may prefer to use this in place of DFS for computing connected components. + ## Problems diff --git a/content/5_Gold/Hashing.mdx b/content/5_Gold/Hashing.mdx deleted file mode 100644 index c61cd73..0000000 --- a/content/5_Gold/Hashing.mdx +++ /dev/null @@ -1,35 +0,0 @@ ---- -id: hashing -title: "Hashing" -author: Benjamin Qi -description: Quickly test equality of substrings with a small probability of failure. -frequency: 1 ---- - -## Tutorial - - - [PAPS 14.3](https://www.csc.kth.se/~jsannemo/slask/main.pdf) - - CPH 26.3 - - [cp-algorithms String Hashing](https://cp-algorithms.com/string/string-hashing.html) - -My implementation can be found [here](https://github.com/bqi343/USACO/blob/master/Implementations/content/strings%20(14)/Light/HashRange%20(14.2).h). It uses two bases rather than just one to decrease the probability that two random strings hash to the same value. As mentioned in the articles above, there is no need to calculate modular inverses. - -## Hacking - - - [Anti-Hash Tests](https://codeforces.com/blog/entry/60442) - - On CodeForces educational rounds in particular, make sure to use random bases. - -## Problems - - - USACO - - [Gold Cownomics](http://www.usaco.org/index.php?page=viewproblem2&cpid=741) - - Use two pointers; for a fixed $l$, keep extending $r$ to the right until the positions $l\ldots r$ explain spotiness. - - Hashing gives you a way to quickly check whether two substrings of different cow types are equal. So for a single $[l,r]$ pair you can check whether it works in $O(N\log N)$ time (and you only need to check $O(M)$ of these pairs in total). - - Actually, it's possible to pass $O(N^2M)$ (or even slower) solutions. - - [Gold Lightsout](http://www.usaco.org/index.php?page=viewproblem2&cpid=599) - - figure out whether this actually needs hashing? (check ...) - - Other (check ...) - - [Palindromic Partitions](https://csacademy.com/contest/ceoi-2017-day-2/task/palindromic-partitions/) - - [Liar](http://codeforces.com/problemset/problem/822/E) [](93) - - [Palindromic Characteristics](http://codeforces.com/problemset/problem/835/D) [](100) - - [Berland SU Computer Network](http://codeforces.com/contest/847/problem/L) [](142) diff --git a/content/5_Gold/MST.mdx b/content/5_Gold/MST.mdx index 84a5a1f..4e8b841 100644 --- a/content/5_Gold/MST.mdx +++ b/content/5_Gold/MST.mdx @@ -21,6 +21,7 @@ export const metadata = { new Problem("Old Silver", "SuperBull", "531", "Easy", false, ["MST"], ""), new Problem("Gold", "Walk", "946", "Easy", false, ["Math","Prim"], ""), new Problem("Gold", "Fencedin", "623", "Easy", false, ["MST"], ""), + new Problem("HR", "Spanning Tree Fraction", "https://www.hackerrank.com/contests/w31/challenges/spanning-tree-fraction/problem", "Easy", false, ["MST", "Binary Search"], ""), new Problem("Plat", "Fencedin", "625", "Normal", false, ["Kruskal"], ""), ], } @@ -33,18 +34,13 @@ export const metadata = { ## Tutorial - - - Similar to Dijkstra + Kruskal's & Prim's + Kruskal's + ## USACO Problems - - -## Other Problems - - - [Birthday Gifts](https://www.hackerearth.com/practice/math/combinatorics/inclusion-exclusion/practice-problems/algorithm/mancunian-and-birthday-gifts-d44faa15/) [](73) - - [Spanning Tree Fraction](https://www.hackerrank.com/contests/w31/challenges/spanning-tree-fraction) [](78) \ No newline at end of file + \ No newline at end of file diff --git a/content/5_Gold/PURQ.mdx b/content/5_Gold/PURQ.mdx index c6d3494..3af5572 100644 --- a/content/5_Gold/PURQ.mdx +++ b/content/5_Gold/PURQ.mdx @@ -14,7 +14,7 @@ export const metadata = { sample: [ new Problem("YS", "Point Set Range Composite", "point_set_range_composite", "Intro", false, ["PURQ"], ""), ], - probs: [ + general: [ new Problem("CSES", "Range Minimum Queries II", "1649", "Intro", false, ["PURQ"], ""), new Problem("Gold", "Springboards", "995", "Normal", false, ["PURQ"], "min segtree"), new Problem("Plat", "Nocross", "721", "Normal", false, ["PURQ"], "LIS variation"), @@ -24,6 +24,8 @@ export const metadata = { +
+ A **segment tree** allows you to do point update and range query in $O(\log N)$ time each for any associative operation. @@ -35,11 +37,11 @@ For gold, you only need to know the basics (ex. sum, min queries). More advanced ### Tutorials - - - - + interactive + simple implementation + same implementation as above + diff --git a/content/5_Gold/PURS.mdx b/content/5_Gold/PURS.mdx index 5d7f3f9..3b98650 100644 --- a/content/5_Gold/PURS.mdx +++ b/content/5_Gold/PURS.mdx @@ -54,9 +54,9 @@ Aka *Fenwick Tree*. ### Tutorials - very good - also very good - extends to range increment and range query, which is covered in plat + interactive + similar to above + also similar to above diff --git a/content/5_Gold/SP.mdx b/content/5_Gold/SP.mdx index 5cf7960..eb2e4da 100644 --- a/content/5_Gold/SP.mdx +++ b/content/5_Gold/SP.mdx @@ -43,12 +43,12 @@ Use *Dijkstra's Algorithm*. ### Tutorial - - CSES 13.2 - - [PAPS 12.3.1](https://www.csc.kth.se/~jsannemo/slask/main.pdf) - - [cp-algo Dijkstra (Dense Graphs)](https://cp-algorithms.com/graph/dijkstra_sparse.html) - - [cp-algo Dijkstra (Sparse Graphs)](https://cp-algorithms.com/graph/dijkstra_sparse.html) - - Usually, it's this one that's applicable. - - [CPC.8](https://github.com/SuprDewd/T-414-AFLV/tree/master/08_graphs_2) + + code + + + + ### $O(M\log N)$ implementation @@ -72,19 +72,30 @@ Can be done in $O(M+N\log N)$ with Fibonacci heap. Use the *Floyd-Warshall* algorithm. -### Standard - - - [CSES Shortest Routes II](https://cses.fi/problemset/task/1672) - ### Tutorial - - CPH 13.3 - - [PAPS 12.3.3](https://www.csc.kth.se/~jsannemo/slask/main.pdf) - - [cp-algo Floyd-Warshall](https://cp-algorithms.com/graph/all-pair-shortest-path-floyd-warshall.html) + + example calculation, code + + + + + + +[Paper](https://arxiv.org/pdf/1904.01210.pdf) + +> A common mistake in implementing the Floyd–Warshall algorithm is to +misorder the triply nested loops (The correct order is `KIJ`). The incorrect +`IJK` and `IKJ` algorithms do not give correct solutions for some instance. However, we can prove that if these are repeated three times, we obtain the correct solutions. +> +> It would be emphasized that these fixes (repeating incorrect algorithms three +times) have the same time complexity as the correct Floyd–Warshall algorithm +up to constant factors. Therefore, our results suggest that, if one is confused by +the order of the triply nested loops, one can repeat the procedure three times +just to be safe. + + ### Problems - - - - [USACO Moortal Cowmbat](http://usaco.org/index.php?page=viewproblem2&cpid=971) - - Use APSP before running DP. \ No newline at end of file + \ No newline at end of file diff --git a/content/5_Gold/SRQ.mdx b/content/5_Gold/SRQ.mdx index e7cee29..0ef55c2 100644 --- a/content/5_Gold/SRQ.mdx +++ b/content/5_Gold/SRQ.mdx @@ -36,8 +36,8 @@ First we'll consider the special case when $\ominus$ denotes `min`. ### Tutorial - - + diagrams + code diff --git a/content/5_Gold/String_Hashing.mdx b/content/5_Gold/String_Hashing.mdx new file mode 100644 index 0000000..a047675 --- /dev/null +++ b/content/5_Gold/String_Hashing.mdx @@ -0,0 +1,61 @@ +--- +id: hashing +title: "Hashing" +author: Benjamin Qi +description: Quickly test equality of substrings with a small probability of failure. +frequency: 1 +--- + +import { Problem } from "../models"; + +export const metadata = { + problems: { + ex: [ + new Problem("Gold", "Cownomics", "741", "Easy", false, [], ""), + ], + general: [ + new Problem("CSA", "Palindromic Partitions", "palindromic-partitions", "Easy", false, ["Greedy", "Hashing"], ""), + new Problem("CF", "Palindromic Characteristics", "problemset/problem/835/D", "Easy", false, ["DP", "Hashing"], ""), + new Problem("CF", "Liar", "problemset/problem/822/E", "Hard", false, ["DP", "Hashing"], ""), + ], + adj: [ + new Problem("CF", "Berland SU Computer Network", "contest/847/problem/L", "Normal", false, [], ""), + ] + } +}; + +## Tutorial + + + good intro + code + many applications + + + +My implementation can be found [here](https://github.com/bqi343/USACO/blob/master/Implementations/content/strings%20(14)/Light/HashRange%20(14.2).h). It uses two bases rather than just one to decrease the probability that two random strings hash to the same value. As mentioned in the articles above, there is no need to calculate modular inverses. + +## Example: Cownomics (Gold) + + + + - Use two pointers; for a fixed $l$, keep extending $r$ to the right until the positions $l\ldots r$ explain spotiness. + - Hashing gives you a way to quickly check whether two substrings of different cow types are equal. So for a single $[l,r]$ pair you can check whether it works in $O(N\log N)$ time (and you only need to check $O(M)$ of these pairs in total). + - Actually, it's possible to pass $O(N^2M)$ (or even slower) solutions. + +## Adjacency Lists + +(elaborate) + + + +## Hacking + + + On CodeForces educational rounds in particular, make sure to randomize your bases. + + +## Problems + + + diff --git a/content/5_Gold/TopoSort.mdx b/content/5_Gold/TopoSort.mdx index b987055..6d17d88 100644 --- a/content/5_Gold/TopoSort.mdx +++ b/content/5_Gold/TopoSort.mdx @@ -37,16 +37,27 @@ To review, a **directed** graph consists of edges that can only be traversed in A [topological sort](https://en.wikipedia.org/wiki/Topological_sorting) of a directed acyclic graph is a linear ordering of its vertices such that for every directed edge $u\to v$ from vertex $u$ to vertex $v$, $u$ comes before $v$ in the ordering. -### Tutorial +## Tutorial + + + both BFS, DFS + + +### DFS DFS DFS - both BFS, DFS +(implementation) + +### BFS + The BFS version, known as [Kahn's Algorithm](https://en.wikipedia.org/wiki/Topological_sorting#Kahn's_algorithm), makes it obvious how to extract the lexicographically minimum topological sort. +(implementation) + ## Dynamic Programming diff --git a/content/5_Gold/Tree_Euler.mdx b/content/5_Gold/Tree_Euler.mdx index c2341ab..b04cdd1 100644 --- a/content/5_Gold/Tree_Euler.mdx +++ b/content/5_Gold/Tree_Euler.mdx @@ -1,12 +1,12 @@ --- id: tree-euler -title: "Euler Tour on Tree" +title: "Euler Tour Technique" author: "?" prerequisites: - Silver - Depth First Search - Gold - Static Range Queries - Gold - Point Update Range Sum -description: Subtree updates and queries as well as a way to compute lowest common ancestors. +description: Flattening a tree into an array. frequency: 2 --- @@ -16,13 +16,13 @@ export const metadata = { problems: { sample: [ new Problem("CSES", "Subtree Queries", "1137", "Easy", false, ["Euler-Tree"], "equivalent to https://judge.yosupo.jp/problem/vertex_add_subtree_sum"), + new Problem("CSES", "Path Queries", "1138", "Easy", false, ["Euler-Tree","PURS"], "equivalent to https://judge.yosupo.jp/problem/vertex_add_path_sum"), ], lca: [ new Problem("CSES", "Company Queries II", "1688", "Easy", false, ["LCA"], ""), + new Problem("CSES", "Distance Queries", "1135", "Easy", false, ["LCA"], ""), ], problems: [ - new Problem("CSES", "Distance Queries", "1135", "Easy", false, ["LCA"], ""), - new Problem("CSES", "Path Queries", "1138", "Easy", false, ["Euler-Tree","PURS"], "equivalent to https://judge.yosupo.jp/problem/vertex_add_path_sum"), new Problem("Gold", "Cow Land", "921", "Normal", false, ["Euler-Tree","PURS", "HLD"], ""), new Problem("Gold", "Milk Visits", "970", "Normal", false, ["Euler-Tree", "LCA"], ""), new Problem("Plat", "Promotion Counting", "696", "Normal", false, ["Euler-Tree","PURS"], ""), @@ -36,19 +36,23 @@ export const metadata = { +If we can preprocess a rooted tree such that every subtree corresponds to a contiguous range on an array, we can do updates and range queries on it! + ### Tutorial - + introduces tree traversal array ## LCA + + ### Tutorial - - + + (implementation) diff --git a/content/6_Plat/Bin_Jump.mdx b/content/6_Plat/Bin_Jump.mdx index 68fd6f1..f5c9a77 100644 --- a/content/6_Plat/Bin_Jump.mdx +++ b/content/6_Plat/Bin_Jump.mdx @@ -42,8 +42,10 @@ export const metadata = { ### Tutorial - - CPH 18.1, 18.3 - - [cp-algorithms](https://cp-algorithms.com/) + + + + diff --git a/content/6_Plat/Centroid.mdx b/content/6_Plat/Centroid.mdx index f66f7a7..0c7f236 100644 --- a/content/6_Plat/Centroid.mdx +++ b/content/6_Plat/Centroid.mdx @@ -26,8 +26,10 @@ export const metadata = { ### Tutorial - - [GeeksForGeeks](http://www.geeksforgeeks.org/centroid-decomposition-of-tree/) - - [Carpanese](https://medium.com/carpanese/an-illustrated-introduction-to-centroid-decomposition-8c1989d53308) + + + + ### Problems diff --git a/content/6_Plat/Geo_Pri.mdx b/content/6_Plat/Geo_Pri.mdx index 0e27d1f..d17059c 100644 --- a/content/6_Plat/Geo_Pri.mdx +++ b/content/6_Plat/Geo_Pri.mdx @@ -2,7 +2,7 @@ id: geo-pri title: "Geometry Primitives" author: Benjamin Qi -description: Basic setup for geometry problems and introduction to line sweep. +description: Basic setup for geometry problems. --- ## Primitives @@ -13,7 +13,7 @@ You should know basic operations like cross product and dot product. For platinu basics, polygon area, point in polygon - + @@ -39,16 +39,3 @@ You should know basic operations like cross product and dot product. For platinu - [Birthday Cake](https://open.kattis.com/problems/birthdaycake) - [Racing Off Track](https://open.kattis.com/contests/acpc17open/problems/racingofftrack) - [TopCoder Watchtower](https://community.topcoder.com/stat?c=problem_statement&pm=2014&rd=4685) - -## Sweep Line - -### Tutorial - - - CPH 30 - - [TopCoder Line Sweep](https://www.topcoder.com/community/competitive-programming/tutorials/line-sweep-algorithms/) - -### Problems - - - [Cow Steepchase II (Silver)](http://www.usaco.org/index.php?page=viewproblem2&cpid=943) - - :| - - [Kattis Closest Pair](https://open.kattis.com/problems/closestpair2) diff --git a/content/6_Plat/HLD.mdx b/content/6_Plat/HLD.mdx index 9f307aa..e47345e 100644 --- a/content/6_Plat/HLD.mdx +++ b/content/6_Plat/HLD.mdx @@ -3,7 +3,7 @@ id: hld title: "Heavy-Light Decomposition" author: Benjamin Qi prerequisites: - - Gold - Euler Tour on Tree + - Gold - Euler Tour Technique - Platinum - Range Update Range Query description: Path and subtree updates and queries. frequency: 1 @@ -14,25 +14,28 @@ import { Problem } from "../models"; export const metadata = { problems: { sample: [ - new Problem("CSES", "Company Queries II", "1688", "Easy", false, ["LCA"], ""), - new Problem("YS","Vertex Set Path Composite","vertex_set_path_composite", "Normal", false, ["HLD"], ""), + new Problem("CSES", "Company Queries II", "1688", "Intro", false, ["LCA"], ""), + new Problem("YS","Vertex Set Path Composite","vertex_set_path_composite", "Easy", false, ["HLD"], ""), ], general: [ - new Problem("Gold", "Cow Land", "921", "Normal", false, ["Euler-Tree","PURS", "HLD"], ""), - new Problem("Plat", "Disrupt", "842", "Easy", false, ["HLD"]), + new Problem("Gold", "Cow Land", "921", "Easy", false, ["Euler-Tree","PURS", "HLD"], ""), + new Problem("Plat", "Disrupt", "842", "Easy", false, ["HLD"], ""), + new Problem("Old Gold", "Grass Planting", "102", "Easy", false, ["HLD"], ""), + new Problem("HR", "Subtrees & Paths", "https://www.hackerrank.com/challenges/subtrees-and-paths", "Easy", false, ["HLD"], ""), + new Problem("ojuz", "JOI - Cats or Dogs", "https://oj.uz/problem/view/JOI18_catdog", "Hard", false, ["HLD"], ""), ], } }; -(computing LCA, path composite) - ## Tutorial - - [Anudeep2011](https://blog.anudeep2011.com/heavy-light-decomposition/) - - [AI-Cash](http://codeforces.com/blog/entry/22072) - - [adamant](https://codeforces.com/blog/entry/53170) + + explains what HLD is (but incomplete & overly complicated code) + + + ## Problems diff --git a/content/6_Plat/Merging.mdx b/content/6_Plat/Merging.mdx index 34c0451..5a95307 100644 --- a/content/6_Plat/Merging.mdx +++ b/content/6_Plat/Merging.mdx @@ -24,10 +24,12 @@ export const metadata = { ## Additional Reading - - CPH 18.4 - Merging Data Structures - - CF Blogs - - [Arpa](https://codeforces.com/blog/entry/44351) - - [tuwuna](https://codeforces.com/blog/entry/67696) + + + + + + # Merging Sets diff --git a/content/6_Plat/Sweep_Line.mdx b/content/6_Plat/Sweep_Line.mdx new file mode 100644 index 0000000..acc33dd --- /dev/null +++ b/content/6_Plat/Sweep_Line.mdx @@ -0,0 +1,34 @@ +--- +id: sweep-line +title: "Sweep Line" +author: Benjamin Qi +description: Introduction to line sweep. +--- + +## Sweep Line + + + + + +### Tutorial + + - CPH 30 + - [TopCoder Line Sweep](https://www.topcoder.com/community/competitive-programming/tutorials/line-sweep-algorithms/) + +## Closest Pair + + - [Kattis Closest Pair](https://open.kattis.com/problems/closestpair2) + +## Line Segment Intersection + + - [Cow Steepchase II (Silver)](http://www.usaco.org/index.php?page=viewproblem2&cpid=943) + - :| + +## Manhattan MST + +https://open.kattis.com/problems/gridmst + +CSA 84 The Sprawl + +TC 760 ComponentsForever \ No newline at end of file diff --git a/content/ordering.ts b/content/ordering.ts index f58fc3f..26975f3 100644 --- a/content/ordering.ts +++ b/content/ordering.ts @@ -155,6 +155,7 @@ const ModuleOrdering: {[key: string]: ModuleOrderingItem[]} = { name: "Geometry", items: [ "geo-pri", + "sweep-line", "hull", "LC", "lagrange",