Merge branch 'master' of https://github.com/thecodingwizard/usaco-training-2.0
This commit is contained in:
commit
b3bb3f8bae
19 changed files with 232 additions and 138 deletions
|
@ -34,10 +34,10 @@ In general, we recommend the following:
|
|||
- For Bronze contestants, any of C++/Java/Python will do.
|
||||
- If you know multiple languages, we recommend you pick C++ over Java, and Java over Python.
|
||||
- For Silver, Gold, and Platinum, we recommend C++/Java.
|
||||
- If you know multiple languages, we recommend you pick C++ over Java since C++ is faster.
|
||||
- It's not guaranteed that you can receive full points for every problem using Python (even for Silver).
|
||||
- If you know multiple languages, we recommend you pick C++ over Java.
|
||||
- Python and Java have trouble passing time limits even for Silver despite the x2 multiplier.
|
||||
- Rewriting the C++ solution for [Wormsort](http://www.usaco.org/index.php?page=viewproblem2&cpid=992) in Python gets TLE on 2/10 cases.
|
||||
- A similar solution in Java requires almost 3s (for a time limit of 4s)
|
||||
- A similar solution in Java requires almost 3s, which is fairly close to the time limit of 4s.
|
||||
|
||||
Note: A majority of high level contestants use C++ and Java. Between those, C++ is more popular.
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ order: 2
|
|||
|
||||
<!-- END DESCRIPTION -->
|
||||
|
||||
(from github)
|
||||
(from my github)
|
||||
|
||||
* Types
|
||||
* Set, Multiset, Unordered Set
|
||||
|
@ -33,7 +33,6 @@ order: 2
|
|||
* Priority Queue (Heap)
|
||||
* Vector
|
||||
* Stack
|
||||
* Bitset
|
||||
* Tutorial
|
||||
* CPH (4, Data Structures)
|
||||
* [C++ Reference](http://www.cplusplus.com/reference/stl/)
|
||||
|
@ -44,4 +43,7 @@ order: 2
|
|||
* [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)
|
||||
* [Tournament](http://codeforces.com/contest/878/problem/C) [](106)
|
||||
|
||||
|
||||
[Blowing up Unordered Map](https://codeforces.com/blog/entry/62393)
|
|
@ -19,3 +19,7 @@ order: 3
|
|||
See 8 of https://www.overleaf.com/project/5e73f65cde1d010001224d8a
|
||||
|
||||
See 12 of https://www.overleaf.com/project/5e73f65cde1d010001224d8a
|
||||
|
||||
|
||||
- [Breaking Java Arrays.sort()](https://codeforces.com/blog/entry/4827)
|
||||
- no longer works, see [this one](https://codeforces.com/contest/1324/submission/73058869) instead
|
|
@ -1,12 +1,10 @@
|
|||
---
|
||||
slug: /silver/dfs
|
||||
title: "DFS"
|
||||
title: "Depth First Search"
|
||||
author: Siyong Huang
|
||||
order: 7
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
- Introduction to Graphs
|
||||
- Depth First Search (DFS)
|
||||
- Flood Fill
|
||||
|
@ -17,10 +15,14 @@ order: 7
|
|||
|
||||
## 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
|
||||
- Recommended
|
||||
- CPH 11
|
||||
- [CSAcademy Graph Intro](https://csacademy.com/lesson/introduction_to_graphs)
|
||||
- [CSAcademy Graph Representations](https://csacademy.com/lesson/graph_representation)
|
||||
- Usually, adjacency lists are used.
|
||||
- Additional
|
||||
- [Topcoder Graphs Pt 1](https://www.topcoder.com/community/data-science/data-science-tutorials/introduction-to-graphs-and-their-data-structures-section-1/)
|
||||
- [Topcoder Graphs Pt 2](https://www.topcoder.com/community/data-science/data-science-tutorials/introduction-to-graphs-and-their-data-structures-section-2/)
|
||||
|
||||
## Depth First Search (DFS)
|
||||
|
||||
|
@ -40,11 +42,23 @@ order: 7
|
|||
|
||||
### Problems
|
||||
|
||||
- [Mootube, Silver (Easy)](http://usaco.org/index.php?page=viewproblem2&cpid=788)
|
||||
- [Closing the Barn, Silver (Easy)](http://usaco.org/index.php?page=viewproblem2&cpid=644)
|
||||
- [Moocast, Silver (Easy)](http://usaco.org/index.php?page=viewproblem2&cpid=668)
|
||||
- [Pails (Normal)](http://usaco.org/index.php?page=viewproblem2&cpid=620)
|
||||
- [Milk Visits (Normal)](http://www.usaco.org/index.php?page=viewproblem2&cpid=968)
|
||||
- CF
|
||||
- [PolandBall & Forest](http://codeforces.com/problemset/problem/755/C) [](56)
|
||||
- [Bear & Friendship](http://codeforces.com/problemset/problem/771/A)
|
||||
- [Journey](http://codeforces.com/contest/839/problem/C) [](54)
|
||||
- DFS on Tree
|
||||
- [Wizard's Tour](http://codeforces.com/contest/860/problem/D) [](59)
|
||||
- USACO
|
||||
- [Mootube, Silver (Easy)](http://usaco.org/index.php?page=viewproblem2&cpid=788)
|
||||
- [Closing the Barn, Silver (Easy)](http://usaco.org/index.php?page=viewproblem2&cpid=644)
|
||||
- [Moocast, Silver (Easy)](http://usaco.org/index.php?page=viewproblem2&cpid=668)
|
||||
- [Pails (Normal)](http://usaco.org/index.php?page=viewproblem2&cpid=620)
|
||||
- [Milk Visits (Normal)](http://www.usaco.org/index.php?page=viewproblem2&cpid=968)
|
||||
- Other
|
||||
- [POI Hotels](https://szkopul.edu.pl/problemset/problem/gDw3iFkeVm7ZA3j_16-XR7jI/site/?key=statement) [](61)
|
||||
- [Kattis Birthday Party (Easy)](https://open.kattis.com/problems/birthday)
|
||||
- DFS with each edge removed
|
||||
|
||||
|
||||
## Flood Fill
|
||||
|
||||
|
@ -104,6 +118,7 @@ void dfs(int node)
|
|||
|
||||
### Problems
|
||||
|
||||
- [CF Bipartiteness](http://codeforces.com/contest/862/problem/B) [](49)
|
||||
- [The Great Revegetation (Normal)](http://usaco.org/index.php?page=viewproblem2&cpid=920)
|
||||
|
||||
## Cycle Detection
|
||||
|
@ -203,4 +218,8 @@ int main()
|
|||
- [Swapity Swapity Swap (Very Hard)](http://www.usaco.org/index.php?page=viewproblem2&cpid=1014)
|
||||
- [CSES Round Trip (undirected)](https://cses.fi/problemset/task/1669)
|
||||
- [CSES Round Trip II (directed)](https://cses.fi/problemset/task/1678)
|
||||
- POI
|
||||
- [Mafia](https://szkopul.edu.pl/problemset/problem/w3YAoAT3ej27YeiaNWjK57_G/site/?key=statement)
|
||||
- [Spies](https://szkopul.edu.pl/problemset/problem/r6tMTfvQFPAEfQioYMCQndQe/site/?key=statement)
|
||||
- [Frog](https://szkopul.edu.pl/problemset/problem/qDH9CkBHZKHY4vbKRBlXPrA7/site/?key=statement)
|
||||
|
||||
|
|
|
@ -17,9 +17,10 @@ Assumes familiarity with prefix sums, recursion, bit operations (for Bitmask DP)
|
|||
|
||||
## Introduction to DP
|
||||
|
||||
* CPH 7
|
||||
* [HackerRank DP](https://www.hackerrank.com/topics/dynamic-programming)
|
||||
* [Topcoder DP](https://www.topcoder.com/community/competitive-programming/tutorials/dynamic-programming-from-novice-to-advanced/)
|
||||
- CPH 7
|
||||
- [HackerRank DP](https://www.hackerrank.com/topics/dynamic-programming)
|
||||
- [Topcoder DP](https://www.topcoder.com/community/competitive-programming/tutorials/dynamic-programming-from-novice-to-advanced/)
|
||||
- [CPC.6](https://github.com/SuprDewd/T-414-AFLV/tree/master/06_dynamic_programming)
|
||||
|
||||
## Classical DP Problems
|
||||
|
||||
|
@ -74,7 +75,7 @@ Note: Has not appeared on recent USACO.
|
|||
|
||||
## Practice Problems
|
||||
|
||||
* [Atcoder DP Contest (Extremely Good)](https://atcoder.jp/contests/dp/tasks)
|
||||
* **[Atcoder DP Contest (Extremely Good)](https://atcoder.jp/contests/dp/tasks)**
|
||||
* [CSES DP Section](https://cses.fi/problemset/list/)
|
||||
* [Codeforces DP Problem List](http://codeforces.com/blog/entry/325)
|
||||
* USACO (Not Ordered By Difficulty)
|
||||
|
|
|
@ -1,84 +1,115 @@
|
|||
---
|
||||
slug: /gold/sp
|
||||
title: "Shortest Path"
|
||||
title: "Shortest Paths"
|
||||
author: Benjamin Qi
|
||||
order: 2
|
||||
---
|
||||
|
||||
<div class="syllabus-only">
|
||||
Description: Todo
|
||||
</div>
|
||||
Assumes familiarity with "Silver - Depth First Search."
|
||||
|
||||
- Breadth First Search
|
||||
- Shortest Path With and Without Negative Edge Weights
|
||||
- All Pairs Shortest Path
|
||||
|
||||
<!-- END DESCRIPTION -->
|
||||
|
||||
[CPC.7](https://github.com/SuprDewd/T-414-AFLV/tree/master/07_graphs_1)
|
||||
|
||||
## Breadth First Search
|
||||
|
||||
Find the shortest path where all edge weights are 1.
|
||||
|
||||
* [CSES Message Route](https://cses.fi/problemset/task/1667)
|
||||
- [CSES Message Route](https://cses.fi/problemset/task/1667)
|
||||
|
||||
### Tutorial
|
||||
|
||||
- CSES 12.2
|
||||
- [CSAcademy BFS](https://csacademy.com/lesson/breadth_first_search)
|
||||
- [cp-algo BFS](https://cp-algorithms.com/graph/breadth-first-search.html)
|
||||
- [cp-algo 0/1 BFS](https://cp-algorithms.com/graph/01_bfs.html)
|
||||
- [KhanAcademy BFS](https://www.khanacademy.org/computing/computer-science/algorithms/breadth-first-search/a/breadth-first-search-and-its-uses)
|
||||
|
||||
### Problems
|
||||
|
||||
- [CSAcademy BFS-DFS](https://csacademy.com/contest/round-41/task/bfs-dfs/) [](50)
|
||||
- [Cow Navigation](http://www.usaco.org/index.php?page=viewproblem2&cpid=695)
|
||||
- [Dream](http://www.usaco.org/index.php?page=viewproblem2&cpid=575)
|
||||
- [Lasers](http://www.usaco.org/index.php?page=viewproblem2&cpid=671)
|
||||
* [Monsters](https://cses.fi/problemset/task/1194)
|
||||
- [Monsters](https://cses.fi/problemset/task/1194)
|
||||
|
||||
## Non-Negative Edge Weights
|
||||
|
||||
* [Kattis SSSP Non-Negative](https://open.kattis.com/problems/shortestpath1)
|
||||
* [CSES Shortest Routes I](https://cses.fi/problemset/task/1671)
|
||||
* [CSES Flight Discount](https://cses.fi/problemset/task/1195)
|
||||
* [CSES Flight Routes](https://cses.fi/problemset/task/1196)
|
||||
* [CSES Investigation](https://cses.fi/problemset/task/1202)
|
||||
|
||||
Use *Dijkstra's Algorithm*.
|
||||
|
||||
### Standard
|
||||
|
||||
- [Kattis SSSP Non-Negative](https://open.kattis.com/problems/shortestpath1)
|
||||
- [CSES Shortest Routes I](https://cses.fi/problemset/task/1671)
|
||||
|
||||
### Tutorial
|
||||
|
||||
* CSES 13.2
|
||||
* [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.
|
||||
- CSES 13.2
|
||||
- [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)
|
||||
|
||||
### USACO Gold Problems
|
||||
### Problems
|
||||
|
||||
* [Milk Pumping](http://www.usaco.org/index.php?page=viewproblem2&cpid=969)
|
||||
* fairly standard application
|
||||
* [Shortcut](http://usaco.org/index.php?page=viewproblem2&cpid=899)
|
||||
* [Fine Dining](http://usaco.org/index.php?page=viewproblem2&cpid=861)
|
||||
- CSES
|
||||
- [CSES Flight Discount](https://cses.fi/problemset/task/1195)
|
||||
- [CSES Flight Routes](https://cses.fi/problemset/task/1196)
|
||||
- [CSES Investigation](https://cses.fi/problemset/task/1202)
|
||||
- USACO
|
||||
- [Milk Pumping](http://www.usaco.org/index.php?page=viewproblem2&cpid=969)
|
||||
- fairly standard application
|
||||
- [Shortcut](http://usaco.org/index.php?page=viewproblem2&cpid=899)
|
||||
- [Fine Dining](http://usaco.org/index.php?page=viewproblem2&cpid=861)
|
||||
- Other
|
||||
- [Lane Switching](https://open.kattis.com/contests/acpc17open/problems/laneswitching)
|
||||
- [Robot Turtles](https://open.kattis.com/problems/robotturtles) [](100)
|
||||
|
||||
## All Pairs Shortest Path (APSP)
|
||||
|
||||
* [CSES Shortest Routes II](https://cses.fi/problemset/task/1672)
|
||||
* [Kattis APSP (with negative weights)](https://open.kattis.com/problems/allpairspath)
|
||||
|
||||
Use the *Floyd-Warshall* algorithm.
|
||||
|
||||
### Standard
|
||||
|
||||
- [CSES Shortest Routes II](https://cses.fi/problemset/task/1672)
|
||||
- [Kattis APSP (with negative weights)](https://open.kattis.com/problems/allpairspath)
|
||||
|
||||
### Tutorial
|
||||
|
||||
* CSES 13.3
|
||||
* [cp-algo Floyd-Warshall](https://cp-algorithms.com/graph/all-pair-shortest-path-floyd-warshall.html)
|
||||
- CPH 13.3
|
||||
- [cp-algo Floyd-Warshall](https://cp-algorithms.com/graph/all-pair-shortest-path-floyd-warshall.html)
|
||||
|
||||
### USACO Gold Problems
|
||||
### Problems
|
||||
|
||||
* [Moortal Cowmbat](http://usaco.org/index.php?page=viewproblem2&cpid=971)
|
||||
* Use APSP before running DP.
|
||||
- [USACO Moortal Cowmbat](http://usaco.org/index.php?page=viewproblem2&cpid=971)
|
||||
- Use APSP before running DP.
|
||||
- [SPOJ Arbitrage](https://www.spoj.com/problems/ARBITRAG/)
|
||||
|
||||
## Negative Edge Weights
|
||||
|
||||
Hasn't appeared in recent USACO Gold as far as I know.
|
||||
Hasn't appeared in recent USACO Gold as far as I know. Usually Bellman-Ford is used. If no negative cycles, can use [Shortest Path Faster Algorithm](https://en.wikipedia.org/wiki/Shortest_Path_Faster_Algorithm) or modify Dijkstra slightly (though the same running time bound no longer applies).
|
||||
|
||||
* [CSES High Score](https://cses.fi/problemset/task/1673)
|
||||
* [Kattis SSSP Negative](https://open.kattis.com/problems/shortestpath3)
|
||||
* [CSES Cycle Finding](https://cses.fi/problemset/task/1197)
|
||||
### Tutorial
|
||||
|
||||
* [cp-algo Bellman Ford](https://cp-algorithms.com/graph/bellman_ford.html)
|
||||
* [Topcoder Graphs Pt 3](https://www.topcoder.com/community/data-science/data-science-tutorials/introduction-to-graphs-and-their-data-structures-section-3/)
|
||||
|
||||
Can also modify Dijkstra's so it works with negative edge weights (but not negative cycles). The same running time bound no longer applies.
|
||||
You can also use shortest path algorithms to solve the following problem (a very simple [linear program](https://en.wikipedia.org/wiki/Linear_programming)).
|
||||
|
||||
> Given variables $x_1,x_2,\ldots,x_N$ with constraints in the form $x_i-x_j\ge c$, compute a feasible solution.
|
||||
|
||||
* [Linear Programming Trick](https://www.cs.rit.edu/~spr/COURSES/ALG/MIT/lec18.pdf)
|
||||
|
||||
### Problems
|
||||
|
||||
- General
|
||||
- [CSES High Score](https://cses.fi/problemset/task/1673)
|
||||
- [Kattis SSSP Negative](https://open.kattis.com/problems/shortestpath3)
|
||||
- [CSES (Negative) Cycle Finding](https://cses.fi/problemset/task/1197)
|
||||
- Simple Linear Programming
|
||||
- [Restore Array](https://oj.uz/problem/view/RMI19_restore)
|
||||
- [Art](https://codeforces.com/gym/102394/problem/A) (basically same as above)
|
||||
- [Timeline (Camp)](https://probgate.org/viewproblem.php?pid=524&cid=80)
|
||||
- equivalent to [Timeline (Gold)](http://www.usaco.org/index.php?page=viewproblem2&cpid=1017) except negative values of $x$ are possible.
|
|
@ -5,21 +5,20 @@ author: Benjamin Qi
|
|||
order: 3
|
||||
---
|
||||
|
||||
<div class="syllabus-only">
|
||||
Description: Todo
|
||||
</div>
|
||||
Assumes familiarity with "Gold - Shortest Paths."
|
||||
|
||||
Disjoint Set Union and Minimum Spanning Tree
|
||||
|
||||
<!-- END DESCRIPTION -->
|
||||
|
||||
Standard Problems:
|
||||
## Standard
|
||||
|
||||
- [Kattis Minimum Spanning Tree](https://open.kattis.com/problems/minspantree)
|
||||
- [CSES Road Reparation](https://cses.fi/problemset/task/1675)
|
||||
- equivalent to above
|
||||
- same as [CSES Road Reparation](https://cses.fi/problemset/task/1675)
|
||||
|
||||
## Tutorial
|
||||
|
||||
- CPH 15
|
||||
- CPH 15 (Spanning Trees)
|
||||
- Prim's Algorithm
|
||||
- [cp-algo](https://cp-algorithms.com/graph/mst_prim.html)
|
||||
- Similar to Dijkstra
|
||||
|
@ -28,6 +27,8 @@ Standard Problems:
|
|||
- [cp-algo 2](https://cp-algorithms.com/graph/mst_kruskal_with_dsu.html)
|
||||
- Requires "Disjoint Set Union" (DSU) data structure
|
||||
- [CSAcademy Disjoint-Set](https://csacademy.com/lesson/disjoint_data_sets)
|
||||
- [Topcoder Union Find](https://www.topcoder.com/community/data-science/data-science-tutorials/disjoint-set-data-structures/)
|
||||
- [CPC.3](https://github.com/SuprDewd/T-414-AFLV/tree/master/03_data_structures)
|
||||
- DSU Complexity Proofs (optional of course)
|
||||
- [log\*n](https://en.wikipedia.org/wiki/Proof_of_O(log*n)\_time_complexity\_of_union%E2%80%93find)
|
||||
- [a(m,n)](https://dl.acm.org/doi/pdf/10.1145/321879.321884)
|
||||
|
@ -44,4 +45,9 @@ Standard Problems:
|
|||
- same as [CSES Road Construction](https://cses.fi/problemset/task/1676)
|
||||
- [Closing the Farm](http://www.usaco.org/index.php?page=viewproblem2&cpid=646)
|
||||
- [Favorite Colors](http://www.usaco.org/index.php?page=viewproblem2&cpid=1042)
|
||||
- fairly tricky
|
||||
- fairly tricky
|
||||
|
||||
## 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)
|
|
@ -5,6 +5,8 @@ author: Benjamin Qi
|
|||
order: 4
|
||||
---
|
||||
|
||||
Assumes familiarity with "Silver - Depth First Search."
|
||||
|
||||
A [topological sort](https://en.wikipedia.org/wiki/Topological_sorting) of a directed 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.
|
||||
|
||||
<!-- END DESCRIPTION -->
|
||||
|
|
|
@ -5,19 +5,18 @@ author: Benjamin Qi
|
|||
order: 5
|
||||
---
|
||||
|
||||
Assumes that you are familiar with prefix sum queries (CPH 9.1).
|
||||
Assumes familiarity with "Silver - Prefix Sums."
|
||||
|
||||
Given an array of size $N$, perform the following tasks in $O(\log N)$ time each:
|
||||
A **Binary Indexed Tree** allows you to perform the following tasks in $O(\log N)$ time each on an array of size $N$:
|
||||
|
||||
- Update the element at a single position (point).
|
||||
- Querying the sum of a prefix of the array.
|
||||
|
||||
The easiest way to do this is with a **Binary Indexed Tree.**
|
||||
<!-- END DESCRIPTION -->
|
||||
|
||||
## Binary Indexed Tree
|
||||
|
||||
Probably the easiest way to do all of these tasks (aka **Fenwick Tree**).
|
||||
Aka **Fenwick Tree**.
|
||||
|
||||
### Sample Problems
|
||||
|
||||
|
|
|
@ -15,4 +15,14 @@ See 13 of https://www.overleaf.com/project/5e73f65cde1d010001224d8a
|
|||
|
||||
- Prime factorization, GCD, LCM
|
||||
- Modular Arithmetic
|
||||
- Fast Exponentiation
|
||||
|
||||
# Binary Exponentiation
|
||||
|
||||
<!-- END DESCRIPTION -->
|
||||
|
||||
* Tutorial
|
||||
* CPH (23, Matrices)
|
||||
* Problems
|
||||
* [Currencies](https://www.hackerrank.com/contests/gs-codesprint/challenges/currencies) [](107)
|
||||
|
||||
COWBASIC
|
|
@ -5,7 +5,7 @@ author: Benjamin Qi
|
|||
order: 1
|
||||
---
|
||||
|
||||
Lowest Common Ancestor and other common tree topics.
|
||||
Lowest Common Ancestor and other tree topics.
|
||||
|
||||
<!-- END DESCRIPTION -->
|
||||
|
||||
|
@ -74,6 +74,10 @@ Other:
|
|||
- [AI-Cash](http://codeforces.com/blog/entry/22072)
|
||||
- [adamant](https://codeforces.com/blog/entry/53170)
|
||||
|
||||
### Problems
|
||||
|
||||
??
|
||||
|
||||
## Small to Large (Offline)
|
||||
|
||||
??
|
|
@ -5,6 +5,8 @@ author: Benjamin Qi
|
|||
order: 2
|
||||
---
|
||||
|
||||
Assumes familiarity with "Gold - Binary Indexed Trees."
|
||||
|
||||
General range queries for associative operations, including segment tree.
|
||||
|
||||
<!-- END DESCRIPTION -->
|
||||
|
@ -33,13 +35,13 @@ 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, 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
|
||||
### Tutorials
|
||||
|
||||
- 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)
|
||||
|
||||
### Problems
|
||||
|
||||
|
@ -52,6 +54,8 @@ This data structure allows you to do point update and range query in $O(\log N)$
|
|||
- [USACO Gold Springboards](http://www.usaco.org/index.php?page=viewproblem2&cpid=995)
|
||||
- can use segment tree with min query in place of the map mentioned in analysis
|
||||
- [POI Cards](https://szkopul.edu.pl/problemset/problem/qpsk3ygf8MU7D_1Es0oc_xd8/site/?key=statement) [](81)
|
||||
- [CSES Area of Rectangles](https://cses.fi/problemset/task/1741)
|
||||
- use segment tree that keeps track of minimum and # of minimums
|
||||
- Lazy Updates
|
||||
- [USACO Old Gold The Lazy Cow](http://www.usaco.org/index.php?page=viewproblem2&cpid=418) (check ...)
|
||||
- [USACO Plat Counting Haybales](http://www.usaco.org/index.php?page=viewproblem2&cpid=578)
|
||||
|
|
|
@ -5,7 +5,9 @@ author: Benjamin Qi
|
|||
order: 3
|
||||
---
|
||||
|
||||
Extend 1D Range Queries to 2D (and beyond).
|
||||
Assumes familiarity with "Platinum - 1D Range Queries."
|
||||
|
||||
Extending 1D Range Queries to 2D (and beyond).
|
||||
|
||||
<!-- END DESCRIPTION -->
|
||||
|
||||
|
|
|
@ -5,43 +5,62 @@ author: Benjamin Qi
|
|||
order: 5
|
||||
---
|
||||
|
||||
Eulerian Tours, SCCs, and BCCs.
|
||||
- Eulerian Tours
|
||||
- SCCs
|
||||
- BCCs
|
||||
|
||||
<!-- END DESCRIPTION -->
|
||||
|
||||
Note: all except the third have not appeared on a recent USACO contest.
|
||||
|
||||
*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)
|
||||
|
||||
## Eulerian Tours
|
||||
|
||||
Has not appeared on a recent USACO contest.
|
||||
|
||||
### Standard
|
||||
|
||||
- [Mail Delivery](https://cses.fi/problemset/task/1691)
|
||||
- Undirected Euler Tour
|
||||
- [Teleporters](https://cses.fi/problemset/task/1693)
|
||||
- Directed Euler Tour
|
||||
|
||||
### Tutorial
|
||||
|
||||
- CPH (19, Path & Circuits)
|
||||
- CPH (19, Path & Circuits)
|
||||
|
||||
### Problems
|
||||
|
||||
- [Matching Substrings](https://csacademy.com/contest/archive/task/matching-substrings/) [](87)
|
||||
- [Matching Substrings](https://csacademy.com/contest/archive/task/matching-substrings/) [](87)
|
||||
|
||||
## Strongly Connected Components
|
||||
|
||||
- Tarjan
|
||||
- [Kosaraju](https://en.wikipedia.org/wiki/Kosaraju%27s_algorithm)
|
||||
- [2-SAT](http://codeforces.com/blog/entry/16205)
|
||||
### Standard
|
||||
|
||||
- [CSES Planets & Kingdoms](https://cses.fi/problemset/task/1683)
|
||||
- find SCCs
|
||||
- [Giant Pizza](https://cses.fi/problemset/task/1684)
|
||||
- 2SAT
|
||||
|
||||
### Tutorial
|
||||
|
||||
- Wikipedia
|
||||
- [Tarjan](https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm)
|
||||
- [Kosaraju](https://en.wikipedia.org/wiki/Kosaraju%27s_algorithm)
|
||||
- CPH (17, Strong Connectivity)
|
||||
- [CPC.7](https://github.com/SuprDewd/T-414-AFLV/tree/master/07_graphs_1)
|
||||
- [CF 2-SAT](http://codeforces.com/blog/entry/16205)
|
||||
|
||||
|
||||
### Problems
|
||||
|
||||
- [Coin Collector](https://cses.fi/problemset/task/1686)
|
||||
- DP on SCCs
|
||||
- [USACO Old Gold: Grass](http://www.usaco.org/index.php?page=viewproblem2&cpid=516)
|
||||
- [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)
|
||||
|
||||
## Biconnected Components
|
||||
|
||||
|
@ -59,6 +78,8 @@ Related topics include
|
|||
|
||||
### Problems
|
||||
|
||||
- [CSES Forbidden Cities](https://cses.fi/problemset/task/1705)
|
||||
- compute block-cut tree
|
||||
- [USACO Plat: Push a Box](http://www.usaco.org/index.php?page=viewproblem2&cpid=769)
|
||||
- [Blockade](https://szkopul.edu.pl/problemset/problem/eDt8w290owtatmCjad0O0ywk/site/?key=statement)
|
||||
- [POLICIJA](http://wcipeg.com/problem/coi06p2)
|
||||
|
|
|
@ -5,7 +5,13 @@ author: Benjamin Qi
|
|||
order: 6
|
||||
---
|
||||
|
||||
Hashing, Tries, Z, KMP, Aho-Corasick, Suffix Array, Manacher
|
||||
- Tries
|
||||
- Hashing
|
||||
- Z
|
||||
- KMP
|
||||
- Manacher
|
||||
- Aho-Corasick
|
||||
- Suffix Array
|
||||
|
||||
<!-- END DESCRIPTION -->
|
||||
|
||||
|
@ -17,6 +23,10 @@ Note: String algorithms do not appear very frequently. Hashing has appeared on g
|
|||
- [CP-Algorithms String Processing: Fundamentals](https://cp-algorithms.com/)
|
||||
- CPH (26, String Algorithms)
|
||||
|
||||
## Tries
|
||||
|
||||
- [Algorithm Gym](http://codeforces.com/blog/entry/15729)
|
||||
|
||||
## Hashing
|
||||
|
||||
Use to quickly test whether two substrings are equal.
|
||||
|
@ -44,10 +54,6 @@ My implementation can be found [here](https://github.com/bqi343/USACO/blob/maste
|
|||
- [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
|
||||
|
@ -55,6 +61,13 @@ My implementation can be found [here](https://github.com/bqi343/USACO/blob/maste
|
|||
- [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/)
|
||||
|
||||
## 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)
|
||||
|
||||
## Aho-Corasick
|
||||
|
||||
- Has appeared in old gold.
|
||||
|
@ -65,10 +78,3 @@ My implementation can be found [here](https://github.com/bqi343/USACO/blob/maste
|
|||
## 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)
|
|
@ -5,7 +5,7 @@ author: Benjamin Qi
|
|||
order: 7
|
||||
---
|
||||
|
||||
Bitset leads to some unintended solutions.
|
||||
Three examples of how bitset leads to some unintended solutions on recent USACO problems.
|
||||
|
||||
<!-- END DESCRIPTION -->
|
||||
|
||||
|
@ -181,4 +181,4 @@ Again, the intended solution runs in $O(N^3)$. Of course, it is still possible t
|
|||
Using operations such as `_Find_first()` and `_Find_next()` mentioned in Errichto's blog above, you can speed up the following:
|
||||
|
||||
* BFSing through a dense graph with $N$ vertices in $O(N^2)$
|
||||
* bipartite matching in $O(N^3)$
|
||||
* bipartite matching in $O(N^3)$
|
|
@ -2,10 +2,10 @@
|
|||
slug: /plat/fracture
|
||||
title: "Fracturing Search"
|
||||
author: Benjamin Qi
|
||||
order: 9
|
||||
order: 8
|
||||
---
|
||||
|
||||
A simpler solution to robotic cow herd that generalizes.
|
||||
A simple solution to [Robotic Cow Herd](http://www.usaco.org/index.php?page=viewproblem2&cpid=674) that generalizes.
|
||||
|
||||
<!-- END DESCRIPTION -->
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
---
|
||||
slug: /plat/matrix
|
||||
title: "Platinum - Matrix Exponentiation"
|
||||
author: ?
|
||||
order: 8
|
||||
---
|
||||
|
||||
Matrix Exponentiation
|
||||
|
||||
<!-- END DESCRIPTION -->
|
||||
|
||||
* Tutorial
|
||||
* CPH (23, Matrices)
|
||||
* Problems
|
||||
* [Currencies](https://www.hackerrank.com/contests/gs-codesprint/challenges/currencies) [](107)
|
||||
|
||||
COWBASIC
|
|
@ -2,12 +2,12 @@
|
|||
slug: /plat/slope
|
||||
title: "Slope Trick"
|
||||
author: Benjamin Qi
|
||||
order: 10
|
||||
order: 9
|
||||
---
|
||||
|
||||
**Slope trick** refers to manipulating piecewise linear convex functions. Includes a simple solution to "Landscaping."
|
||||
**Slope trick** refers to manipulating piecewise linear convex functions. Includes a simple solution to [Landscaping](http://www.usaco.org/index.php?page=viewproblem2&cpid=650).
|
||||
|
||||
<!-- END EXCERPT -->
|
||||
<!-- END DESCRIPTION -->
|
||||
|
||||
## Tutorials
|
||||
|
||||
|
@ -123,7 +123,7 @@ int main() {
|
|||
```
|
||||
</details>
|
||||
|
||||
## Landscaping
|
||||
## [Landscaping](http://www.usaco.org/index.php?page=viewproblem2&cpid=650)
|
||||
|
||||
This is quite similar to the previous task, so it's easy to guess that slope trick is applicable.
|
||||
|
||||
|
@ -190,16 +190,16 @@ int main() {
|
|||
|
||||
## Problems
|
||||
|
||||
* [Moving Haybales (USACO Camp)](https://probgate.org/viewproblem.php?pid=247)
|
||||
* [Wall](https://atcoder.jp/contests/kupc2016/tasks/kupc2016_h)
|
||||
* same as "Potatoes"
|
||||
* [Stock Trading (USACO Camp)](https://probgate.org/viewproblem.php?pid=531&cid=81)
|
||||
* extension of "Buy Low Sell High"
|
||||
* [Bookface](https://codeforces.com/group/ZFgXbZSjvp/contest/274852/problem/C)
|
||||
* [CCDSAP Exam](https://www.codechef.com/problems/CCDSAP)
|
||||
* [Farm of Monsters](https://codeforces.com/gym/102538/problem/F)
|
||||
* [Moving Walkways](https://codeforces.com/contest/1209/problem/H)
|
||||
* [April Fools' Problem](https://codeforces.com/contest/802/problem/O)
|
||||
* [Conquer the World](https://icpc.kattis.com/problems/conquertheworld)
|
||||
* note: ICPC world finals, 0 solves in contest
|
||||
* "Potatoes" on tree!!
|
||||
- [Moving Haybales (USACO Camp)](https://probgate.org/viewproblem.php?pid=247)
|
||||
- [Wall](https://atcoder.jp/contests/kupc2016/tasks/kupc2016_h)
|
||||
- same as "Potatoes"
|
||||
- [Stock Trading (USACO Camp)](https://probgate.org/viewproblem.php?pid=531&cid=81)
|
||||
- extension of "Buy Low Sell High"
|
||||
- [Bookface](https://codeforces.com/group/ZFgXbZSjvp/contest/274852/problem/C)
|
||||
- [CCDSAP Exam](https://www.codechef.com/problems/CCDSAP)
|
||||
- [Farm of Monsters](https://codeforces.com/gym/102538/problem/F)
|
||||
- [Moving Walkways](https://codeforces.com/contest/1209/problem/H)
|
||||
- [April Fools' Problem](https://codeforces.com/contest/802/problem/O)
|
||||
- [Conquer the World](https://icpc.kattis.com/problems/conquertheworld)
|
||||
- note: ICPC world finals, 0 solves in contest
|
||||
- "Potatoes" on tree!!
|
Reference in a new issue