+ plat stuff
This commit is contained in:
parent
3448e8aa03
commit
20a2e21e77
12 changed files with 268 additions and 46 deletions
|
@ -18,4 +18,41 @@ author: Unknown
|
|||
- Multiset (F FOR JAVA) (just teach a workaround or smthn ig) TreeMap<value,numoccrances> (erase by value pitfall)
|
||||
- Custom comparator (prerequisite for basically all silver topics in Java)
|
||||
- HashSets / HashMaps
|
||||
- ex?
|
||||
- ex?
|
||||
|
||||
|
||||
|
||||
(from github)
|
||||
|
||||
# STL
|
||||
|
||||
## 2
|
||||
|
||||
* Types
|
||||
* Set, Multiset, Unordered Set
|
||||
* Map, Unordered Map (Hashmap)
|
||||
* see STL demo
|
||||
* Queue, Deque, Linked List
|
||||
* Priority Queue (Heap)
|
||||
* Vector
|
||||
* Stack
|
||||
* Bitset
|
||||
* Tutorial
|
||||
* CPH (4, Data Structures)
|
||||
* [C++ Reference](http://www.cplusplus.com/reference/stl/)
|
||||
* [CPC.2](https://github.com/SuprDewd/T-414-AFLV/tree/master/02_data_structures)
|
||||
* Problems (sorted by length)
|
||||
* [Beautiful Triplets](https://www.hackerearth.com/practice/algorithms/greedy/basics-of-greedy-algorithms/practice-problems/algorithm/mancunian-and-beautiful-triplets-30968257/) [](54)
|
||||
* [Polycarp's Phone Book](http://codeforces.com/contest/860/problem/B) [](56)
|
||||
* [Jury Marks](http://codeforces.com/contest/831/problem/C) [](67)
|
||||
* [Mahmoud & Ehab & Function](http://codeforces.com/contest/862/problem/E) [](74)
|
||||
* [Karen & Cards](http://codeforces.com/contest/815/problem/D) [](86)
|
||||
* [Tournament](http://codeforces.com/contest/878/problem/C) [](106)
|
||||
|
||||
# 4
|
||||
|
||||
* Order Statistics Tree
|
||||
* [Codeforces Tutorial](http://codeforces.com/blog/entry/11080)
|
||||
* Good to know for gold, sometimes can be used in place of BIT
|
||||
* Rope
|
||||
* [Codeforces Tutorial](https://codeforces.com/blog/entry/10355)
|
||||
|
|
|
@ -18,9 +18,10 @@ Author: Siyong Huang
|
|||
|
||||
## Prerequisites
|
||||
|
||||
- [CSAcademy Graph Theory](https://csacademy.com/lesson/introduction_to_graphs)
|
||||
- [CSAcademy Graph Intro](https://csacademy.com/lesson/introduction_to_graphs)
|
||||
- [CSAcademy Graph Representations](https://csacademy.com/lesson/graph_representation)
|
||||
- Note: DFS is most commonly implemented with adjacency lists.
|
||||
- CPH 11
|
||||
|
||||
## Depth First Search (DFS)
|
||||
|
||||
|
@ -31,11 +32,12 @@ Author: Siyong Huang
|
|||
### Tutorial
|
||||
|
||||
- Recommended:
|
||||
- CPH 12.1
|
||||
- [CSAcademy DFS](https://csacademy.com/lesson/depth_first_search/)
|
||||
- Additional:
|
||||
- CPH Chapter 12
|
||||
- [cp-algo DFS](https://cp-algorithms.com/graph/depth-first-search.html)
|
||||
- hard to parse if this is your first time learning about DFS
|
||||
- [CPC.7](https://github.com/SuprDewd/T-414-AFLV/tree/master/07_graphs_1)
|
||||
|
||||
### Problems
|
||||
|
||||
|
@ -47,7 +49,7 @@ Author: Siyong Huang
|
|||
|
||||
## Flood Fill
|
||||
|
||||
*Flood Fill* refers to finding the number of connected components in a graph, usually when the graph is a grid.
|
||||
[Flood Fill](https://en.wikipedia.org/wiki/Flood_fill) refers to finding the number of connected components in a graph, usually when the graph is a grid.
|
||||
|
||||
- [CSES Counting Rooms](https://cses.fi/problemset/task/1192)
|
||||
- [CSES Labyrinth](https://cses.fi/problemset/task/1193)
|
||||
|
@ -115,8 +117,8 @@ A related topic is **strongly connected components**, a platinum level concept.
|
|||
|
||||
Links:
|
||||
|
||||
* CPH 16.3: successor paths
|
||||
* CPH 16.4: cycle detection in successor graph
|
||||
- CPH 16.3: successor paths
|
||||
- CPH 16.4: cycle detection in successor graph
|
||||
|
||||
In silver-level directed cycle problems, it is generally the case that each node has exactly one edge going out of it. This is known as a **successor graph** or a **functional graph.**
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
---
|
||||
slug: /gold/hashing
|
||||
title: "Gold - Hashing"
|
||||
author: Benjamin Qi
|
||||
---
|
||||
|
||||
# Gold - Hashing
|
||||
|
||||
Author: Benjamin Qi
|
||||
|
||||
## Hashing
|
||||
|
||||
Use to quickly test whether two substrings are equal.
|
||||
|
||||
- Tutorial
|
||||
- CPH 26.3
|
||||
- [cp-algorithms String Hashing](https://cp-algorithms.com/string/string-hashing.html)
|
||||
- [Anti-Hash Tests](https://codeforces.com/blog/entry/60442)
|
||||
- On CodeForces educational rounds in particular, make sure to use random bases.
|
||||
|
||||
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.
|
||||
|
||||
### USACO Gold Problems (ok def need more)
|
||||
|
||||
- [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).
|
||||
- [Lightsout](http://www.usaco.org/index.php?page=viewproblem2&cpid=599)
|
||||
- figure out whether this actually needs hashing? (haven't implemented)
|
|
@ -4,18 +4,24 @@ title: "Gold - Topological Sort"
|
|||
author: Benjamin Qi
|
||||
---
|
||||
|
||||
## Gold - Topological Sort
|
||||
# Gold - [Topological Sort](https://en.wikipedia.org/wiki/Topological_sorting)
|
||||
|
||||
Author: Benjamin Qi
|
||||
|
||||
- [CSES Course Schedule](https://cses.fi/problemset/task/1679)
|
||||
- [CSES Longest Flight Route](https://cses.fi/problemset/task/1680)
|
||||
- [CSES Game Routes](https://cses.fi/problemset/task/1681)
|
||||
|
||||
### Tutorial
|
||||
## Tutorial
|
||||
|
||||
- CPH 16.1, 16.2
|
||||
- [cp-algorithms](https://cp-algorithms.com/graph/topological-sort.html)
|
||||
|
||||
### USACO Gold Problems
|
||||
## Problems
|
||||
|
||||
- [Timeline](http://www.usaco.org/index.php?page=viewproblem2&cpid=1017)
|
||||
- [Milking Order](http://www.usaco.org/index.php?page=viewproblem2&cpid=838)
|
||||
- USACO Gold
|
||||
- [Timeline](http://www.usaco.org/index.php?page=viewproblem2&cpid=1017)
|
||||
- [Milking Order](http://www.usaco.org/index.php?page=viewproblem2&cpid=838)
|
||||
- Other
|
||||
- [Minimal Labels](http://codeforces.com/contest/825/problem/E) [](53)
|
||||
- [Quantum](https://open.kattis.com/contests/acpc17open/problems/quantumsuperposition) [](84)
|
|
@ -33,11 +33,12 @@ Author: Benjamin Qi
|
|||
This data structure allows you to do point update and range query in $O(\log N)$ time each for any associative operation. In particular, note that **lazy** updates allow you to range updates as well.
|
||||
|
||||
- Tutorial
|
||||
- CPH 9.3
|
||||
- CPH 9.3, 28.1 (Segment Trees Revisited)
|
||||
- [Codeforces Tutorial](http://codeforces.com/blog/entry/18051)
|
||||
- [CSAcademy Tutorial](https://csacademy.com/lesson/segment_trees/)
|
||||
- [cp-algorithms](https://cp-algorithms.com/data_structures/segment_tree.html)
|
||||
- [Slides from CPC.3](https://github.com/SuprDewd/T-414-AFLV/tree/master/03_data_structures)
|
||||
- Special: Minimum Query w/ Number of Minimums
|
||||
|
||||
|
||||
### Problems
|
||||
|
@ -69,4 +70,4 @@ Example problem:
|
|||
|
||||
You can extend this to higher dimensions as well (USACO Camp - "Cows Play Global Thermonuclear War").
|
||||
|
||||
- [Paper](https://arxiv.org/pdf/1311.6093.pdf)
|
||||
- [Paper](https://arxiv.org/pdf/1311.6093.pdf)
|
|
@ -33,6 +33,8 @@ See [my implementations](https://github.com/bqi343/USACO/tree/master/Implementat
|
|||
|
||||
- Short Description
|
||||
- CSES 28.2, 28.4
|
||||
- Segment Tree (or BIT) nested inside segment tree
|
||||
- use 2D offline BIT whenever possible rather than an online 2D segment tree (faster, lower memory)
|
||||
- Problems
|
||||
- [USACO Plat Friendcross](http://www.usaco.org/index.php?page=viewproblem2&cpid=722)
|
||||
- [USACO Plat Mowing](http://www.usaco.org/index.php?page=viewproblem2&cpid=601)
|
||||
|
|
|
@ -47,4 +47,53 @@ You should know basic operations like cross product and dot product. For platinu
|
|||
- [USACO Old Gold - Fencing](http://www.usaco.org/index.php?page=viewproblem2&cpid=534)
|
||||
- [USACO Old Gold - Cow Curling](http://www.usaco.org/index.php?page=viewproblem2&cpid=382)
|
||||
- [AGC 44 Random Pawn](https://atcoder.jp/contests/agc044/tasks/agc044_e)
|
||||
- Generalization of "Balance"
|
||||
- Generalization of "Balance"
|
||||
|
||||
(old)
|
||||
|
||||
|
||||
[CPC.12](https://github.com/SuprDewd/T-414-AFLV/tree/master/12_geometry)
|
||||
|
||||
## 4
|
||||
* Misc Stuff to Know
|
||||
* Topics
|
||||
* std::complex, pair operators
|
||||
* Closest Pair
|
||||
* MaxCollinear
|
||||
* Point in Polygon
|
||||
* Polygon Area
|
||||
* Line Segment Intersection
|
||||
* Tutorial
|
||||
* [TopCoder](https://www.topcoder.com/community/data-science/data-science-tutorials/geometry-concepts-basic-concepts/)
|
||||
* [Point Class](http://codeforces.com/blog/entry/48122)
|
||||
* [Easy Geo w/ std::complex](http://codeforces.com/blog/entry/22175)
|
||||
* [Geo Book](http://codeforces.com/blog/entry/59129)
|
||||
* CPH (29, Geometry)
|
||||
* Problems
|
||||
* [Arpa & Geo](http://codeforces.com/problemset/problem/851/B)
|
||||
* [Tell Your World](http://codeforces.com/problemset/problem/849/B)
|
||||
* [Gleb & Pizza](http://codeforces.com/problemset/problem/842/B)
|
||||
* [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)
|
||||
* Convex Hull
|
||||
* Tutorial
|
||||
* CPH (30, Sweep Line Algorithms)
|
||||
* [TopCoder Line Sweep](https://www.topcoder.com/community/data-science/data-science-tutorials/line-sweep-algorithms/)
|
||||
* Topics
|
||||
* Convex Hull
|
||||
* [Wikipedia](https://en.wikipedia.org/wiki/Convex_hull_algorithms)
|
||||
* Andrew's Monotone Chain (I prefer)
|
||||
* Graham Scan
|
||||
* Additional
|
||||
* [Lichao Segment Tree](http://codeforces.com/blog/entry/51275?#comment-351510)
|
||||
* Half-Plane Intersection
|
||||
* [Blogewoosh (Ternary Search)](https://codeforces.com/blog/entry/61710)
|
||||
* [retrograd](https://codeforces.com/blog/entry/61710?#comment-457662)
|
||||
* [Petr (Linear](https://petr-mitrichev.blogspot.com/2016/07/a-half-plane-week.html)
|
||||
* LineContainer
|
||||
* maintaining separate ones for bottom and top hulls should suffice?
|
||||
* Problem(s)
|
||||
* [Bridges](https://csacademy.com/contest/archive/task/building-bridges/)
|
||||
* [Fence Orthogonality](https://open.kattis.com/problems/fenceortho)
|
||||
* [A2OJ](https://a2oj.com/category?ID=22)
|
||||
|
|
|
@ -10,4 +10,44 @@ SCC
|
|||
|
||||
BCC
|
||||
|
||||
[USACO Plat Push a Box](http://www.usaco.org/index.php?page=viewproblem2&cpid=769)
|
||||
[USACO Plat Push a Box](http://www.usaco.org/index.php?page=viewproblem2&cpid=769)
|
||||
|
||||
|
||||
*Some problems sourced from [here](http://codeforces.com/blog/entry/54526?#comment-385354).*
|
||||
|
||||
[CPC.10](https://github.com/SuprDewd/T-414-AFLV/tree/master/10_graphs_3_network_flow)
|
||||
|
||||
## 4
|
||||
* Eulerian Tours
|
||||
* Tutorial
|
||||
* CPH (19, Path & Circuits)
|
||||
* Problems
|
||||
* [Matching Substrings](https://csacademy.com/contest/archive/task/matching-substrings/) [](87)
|
||||
* [A2OJ](https://a2oj.com/category?ID=24)
|
||||
* Biconnected Components
|
||||
* Related
|
||||
* Articulation Points
|
||||
* Bridges
|
||||
* Block-Cut Tree
|
||||
* Tutorial
|
||||
* [GeeksforGeeks](http://www.geeksforgeeks.org/articulation-points-or-cut-vertices-in-a-graph/)
|
||||
* [Wikipedia](https://en.wikipedia.org/wiki/Biconnected_component)
|
||||
* [CF DFS Tree + Bridges](https://codeforces.com/blog/entry/68138)
|
||||
* Problems
|
||||
* [Blockade](https://szkopul.edu.pl/problemset/problem/eDt8w290owtatmCjad0O0ywk/site/?key=statement)
|
||||
* [POLICIJA](http://wcipeg.com/problem/coi06p2)
|
||||
* [One-Way Streets](https://csacademy.com/contest/archive/task/one-way-streets/)
|
||||
* [Investment](https://dmoj.ca/problem/tle17c1p6)
|
||||
* [A2OJ](https://a2oj.com/category?ID=128)
|
||||
* Strongly Connected Components
|
||||
* Tutorial
|
||||
* CPH (17, Strong Connectivity)
|
||||
* Topics
|
||||
* Tarjan
|
||||
* [Kosaraju](https://en.wikipedia.org/wiki/Kosaraju%27s_algorithm)
|
||||
* [2-SAT](http://codeforces.com/blog/entry/16205)
|
||||
* Problems
|
||||
* [A2OJ](https://a2oj.com/category?ID=231)
|
||||
* [Proving Equivalences](https://open.kattis.com/problems/equivalences) [](78)
|
||||
* [Festival](https://szkopul.edu.pl/problemset/problem/p9uJo01RR9ouMLLAYroFuQ-7/site/?key=statement) [](173)
|
||||
* [Linear Programming Trick](https://www.cs.rit.edu/~spr/COURSES/ALG/MIT/lec18.pdf)
|
||||
|
|
14
content/4_Plat/Plat_Matrix.md
Normal file
14
content/4_Plat/Plat_Matrix.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
slug: /plat/matrix
|
||||
title: "Platinum - Matrices"
|
||||
author: ?
|
||||
---
|
||||
|
||||
Exponentiation
|
||||
|
||||
* Tutorial
|
||||
* CPH (23, Matrices)
|
||||
* Problems
|
||||
* [Currencies](https://www.hackerrank.com/contests/gs-codesprint/challenges/currencies) [](107)
|
||||
|
||||
COWBASIC
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
slug: /plat/slope
|
||||
title: "Plat - Slope Trick"
|
||||
title: "Platinum - Slope Trick"
|
||||
author: Benjamin Qi
|
||||
---
|
||||
|
||||
|
@ -24,7 +24,7 @@ From the latter link (modified):
|
|||
|
||||
It's generally applicable as a DP optimization. Usually you can come up with a slower DP (ex. $O(N^2)$) first and then optimize it to $O(N\log N)$ with slope trick.
|
||||
|
||||
This document assumes some familiarity with at least one of the links above.
|
||||
This document assumes some familiarity with at least one of the links above (and provides a few more examples).
|
||||
|
||||
## A Simple Example
|
||||
|
||||
|
|
73
content/4_Plat/Plat_Strings.md
Normal file
73
content/4_Plat/Plat_Strings.md
Normal file
|
@ -0,0 +1,73 @@
|
|||
---
|
||||
slug: /plat/hashing
|
||||
title: "Platinum - Strings"
|
||||
author: Benjamin Qi
|
||||
---
|
||||
|
||||
# Platinum - Strings
|
||||
|
||||
Author: Benjamin Qi
|
||||
|
||||
Note: String algorithms do not appear very frequently. Hashing has appeared on gold (rarely).
|
||||
|
||||
## General Resources
|
||||
|
||||
- [CPC.11](https://github.com/SuprDewd/T-414-AFLV/tree/master/11_strings)
|
||||
- [CP-Algorithms String Processing: Fundamentals](https://cp-algorithms.com/)
|
||||
- CPH (26, String Algorithms)
|
||||
|
||||
## Hashing
|
||||
|
||||
Use to quickly test whether two substrings are equal.
|
||||
|
||||
- Tutorial
|
||||
- CPH 26.3
|
||||
- [cp-algorithms String Hashing](https://cp-algorithms.com/string/string-hashing.html)
|
||||
- [Anti-Hash Tests](https://codeforces.com/blog/entry/60442)
|
||||
- On CodeForces educational rounds in particular, make sure to use random bases.
|
||||
|
||||
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.
|
||||
|
||||
### 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)
|
||||
|
||||
## Tries
|
||||
|
||||
- [Algorithm Gym](http://codeforces.com/blog/entry/15729)
|
||||
|
||||
## Z, KMP
|
||||
|
||||
- Tutorial
|
||||
- [paladin8](http://codeforces.com/blog/entry/3107)
|
||||
- [GeeksForGeeks](http://www.geeksforgeeks.org/searching-for-patterns-set-2-kmp-algorithm/)
|
||||
- [TopCoder](https://www.topcoder.com/community/data-science/data-science-tutorials/introduction-to-string-searching-algorithms/)
|
||||
|
||||
## Aho-Corasick
|
||||
|
||||
- Has appeared in old gold.
|
||||
- Tutorial
|
||||
- [adamant](http://codeforces.com/blog/entry/14854)
|
||||
- [GeeksForGeeks](http://www.geeksforgeeks.org/aho-corasick-algorithm-pattern-searching/)
|
||||
|
||||
## Suffix Array
|
||||
|
||||
- [USACO Plat - Standing Out from the Herd](http://www.usaco.org/index.php?page=viewproblem2&cpid=768)
|
||||
|
||||
## Manacher
|
||||
|
||||
- Has appeared at camp but not in platinum.
|
||||
- [HackerRank](https://www.hackerrank.com/topics/manachers-algorithm)
|
||||
- [adamant](http://codeforces.com/blog/entry/12143)
|
||||
- [cp-algorithms](https://cp-algorithms.com/string/manacher.html)
|
|
@ -16,6 +16,7 @@ author: Benjamin Qi
|
|||
|
||||
- [USACO Plat Newbarns](http://www.usaco.org/index.php?page=viewproblem2&cpid=817)
|
||||
- Copy of [Brain Network "Hard"](https://codeforces.com/contest/690/problem/C3)
|
||||
- [Tree Construction](https://csacademy.com/contest/archive/task/tree-construct)
|
||||
|
||||
## Lowest Common Ancestor
|
||||
|
||||
|
@ -26,6 +27,8 @@ author: Benjamin Qi
|
|||
|
||||
### Problems
|
||||
|
||||
USACO:
|
||||
|
||||
- [USACO Plat Max Flow](http://www.usaco.org/index.php?page=viewproblem2&cpid=576)
|
||||
- [USACO Gold Milk Visits](http://www.usaco.org/index.php?page=viewproblem2&cpid=970)
|
||||
- [USACO Gold Cow Land](http://www.usaco.org/index.php?page=viewproblem2&cpid=921)
|
||||
|
@ -40,10 +43,34 @@ author: Benjamin Qi
|
|||
- [USACO Plat Exercise](http://www.usaco.org/index.php?page=viewproblem2&cpid=901)
|
||||
- tricky
|
||||
|
||||
Other:
|
||||
|
||||
- [Hot & Cold](https://dmoj.ca/problem/bts17p7) [](105)
|
||||
- [Root LCA Queries](https://csacademy.com/contest/archive/task/root-lca-queries/) [](107)
|
||||
|
||||
## Centroid Decomposition
|
||||
|
||||
### Tutorial
|
||||
|
||||
- [GeeksForGeeks](http://www.geeksforgeeks.org/centroid-decomposition-of-tree/)
|
||||
- [Carpanese](https://medium.com/carpanese/an-illustrated-introduction-to-centroid-decomposition-8c1989d53308)
|
||||
|
||||
### Problems
|
||||
|
||||
- [USACO Plat - At Large](http://www.usaco.org/index.php?page=viewproblem2&cpid=793)
|
||||
- very tricky
|
||||
- [DMOJ Bob Equilibrium](https://dmoj.ca/problem/dmopc19c7p6)
|
||||
|
||||
## Heavy-Light Decomposition
|
||||
|
||||
- probably not intended solution, but can help (ex. for "Disrupt")
|
||||
|
||||
### Tutorial
|
||||
|
||||
- [Anudeep2011](https://blog.anudeep2011.com/heavy-light-decomposition/)
|
||||
- [AI-Cash](http://codeforces.com/blog/entry/22072)
|
||||
- [adamant](https://codeforces.com/blog/entry/53170)
|
||||
|
||||
## Small to Large (Offline)
|
||||
|
||||
??
|
Reference in a new issue