resolve merge

This commit is contained in:
Nathan Wang 2020-06-24 14:11:48 -07:00
commit 4181782de2
25 changed files with 353 additions and 248 deletions

View file

@ -180,8 +180,15 @@ fout.write(str(ans))
The following require relatively little programming experience and no algorithmic knowledge. Do as many as you want, then move on! You do not have to do all of them.
- [Promotion Counting](http://usaco.org/index.php?page=viewproblem2&cpid=591)
- [Word Processor](http://usaco.org/index.php?page=viewproblem2&cpid=987)
- [Square Pasture](http://usaco.org/index.php?page=viewproblem2&cpid=663)
- [CSES Introductory Problems](https://cses.fi/problemset/list/)
- up to and including "Palindrome Reorder"
<problems-list>
<problem name="Promotion Counting" usaco="591" difficulty="Intro">
Can also do range XOR queries w/ update.
</problem>
<problem name="Word Processor" usaco="987" difficulty="Intro">
</problem>
<problem name="Square Pasture" usaco="663" difficulty="Intro">
</problem>
</problems-list>
Also check the [CSES Introductory Problems](https://cses.fi/problemset/list/) up to and including "Palindrome Reorder."

View file

@ -33,7 +33,7 @@ Print one integer, the square of the maximum Euclidean distance between any two
### Solution
We can brute-force every pair of points and find the square of the distance between them, by squaring the formula for Euclidean distance: $\text{distance}^2 = (x_2-x_1)^2 + (y_2-y_1)^2$. Thus, we store the coordinates in arrays \mintinline{java}{X[]} and \mintinline{java}{Y[]}, such that \mintinline{java}{X[i]} and \mintinline{java}{Y[i]} are the $x$- and $y$-coordinates of the $i_{th}$ point, respectively. Then, we iterate through all possible pairs of points, using a variable max to store the maximum square of distance between any pair seen so far, and if the square of the distance between a pair is greater than our current maximum, we set our current maximum to it.
We can brute-force every pair of points and find the square of the distance between them, by squaring the formula for Euclidean distance: $\text{distance}^2 = (x_2-x_1)^2 + (y_2-y_1)^2$. Thus, we store the coordinates in arrays `X[]` and `Y[]`, such that `X[i]` and `Y[i]` are the $x$- and $y$-coordinates of the $i_{th}$ point, respectively. Then, we iterate through all possible pairs of points, using a variable max to store the maximum square of distance between any pair seen so far, and if the square of the distance between a pair is greater than our current maximum, we set our current maximum to it.
Java:
@ -67,7 +67,10 @@ for(int i = 0; i < n; i++){ // for each first point
cout << high << endl;
```
A couple notes: first, since we're iterating through all pairs of points, we start the $j$ loop from $j = i+1$ so that point $i$ and point $j$ are never the same point. Furthermore, it makes it so that each pair is only counted once. In this problem, it doesn't matter whether we double-count pairs or whether we allow $i$ and $j$ to be the same point, but in other problems where we're counting something rather than looking at the maximum, it's important to be careful that we don't overcount. Secondly, the problem asks for the square of the maximum Euclidean distance between any two points. Some students may be tempted to maintain the maximum distance in a variable, and then square it at the end when outputting. However, the problem here is that while the square of the distance between two integer points is always an integer, the distance itself isn't guaranteed to be an integer. Thus, we'll end up shoving a non-integer value into an integer variable, which truncates the decimal part. Using a floating point variable isn't likely to work either, due to precision errors (use of floating point decimals should generally be avoided when possible).
A couple notes:
- First, since we're iterating through all pairs of points, we start the $j$ loop from $j = i+1$ so that point $i$ and point $j$ are never the same point. Furthermore, it makes it so that each pair is only counted once. In this problem, it doesn't matter whether we double-count pairs or whether we allow $i$ and $j$ to be the same point, but in other problems where we're counting something rather than looking at the maximum, it's important to be careful that we don't overcount.
- Secondly, the problem asks for the square of the maximum Euclidean distance between any two points. Some students may be tempted to maintain the maximum distance in a variable, and then square it at the end when outputting. However, the problem here is that while the square of the distance between two integer points is always an integer, the distance itself isn't guaranteed to be an integer. Thus, we'll end up shoving a non-integer value into an integer variable, which truncates the decimal part. Using a floating point variable isn't likely to work either, due to precision errors (use of floating point decimals should generally be avoided when possible).
(Ben - have you verified this claim?)
@ -79,7 +82,9 @@ In Java, we'll have to implement this ourselves, which is called [Heap's Algorit
As an example, here are the permutations generated by Heap's Algorithm for \([1, 2, 3]\):
$$[1, 2, 3], [2, 1, 3], [3, 1, 2], [1, 3, 2], [2, 3, 1], [3, 2, 1]$$
$$
[1, 2, 3], [2, 1, 3], [3, 1, 2], [1, 3, 2], [2, 3, 1], [3, 2, 1]
$$
Code for iterating over all permutations is as follows:
@ -110,33 +115,57 @@ do {
} while(next_permutation(v.begin(), v.end()));
```
Note that this generates the permutations in **lexicographical order** (explanation)
## Problems
- CSES
- [Creating Strings I](https://cses.fi/problemset/task/1622)
- [Apple Division](https://cses.fi/problemset/task/1623)
- [Chessboard and Queens](https://cses.fi/problemset/task/1624)
<problems-list>
<problem name="Creating Strings I" cses="1622" difficulty="Intro" tags={[]}>
</problem>
<problem name="Apple Division" cses="1623" difficulty="Intro" tags={[]}>
</problem>
<problem name="Chessboard and Queens" cses="1624" difficulty="Easy" tags={[]}>
- go through all permutations
</problem>
</problems-list>
- USACO Bronze
- [Triangles](http://usaco.org/index.php?page=viewproblem2&cpid=1011)
- [Photoshoot](http://www.usaco.org/index.php?page=viewproblem2&cpid=988)
- Hint: Figure out what exactly you're complete searching
- [Cow Gymnastics](http://usaco.org/index.php?page=viewproblem2&cpid=963)
- Hint: Brute force over all possible pairs
- [Milk Pails](http://usaco.org/index.php?page=viewproblem2&cpid=615)
- [Lifeguards](http://usaco.org/index.php?page=viewproblem2&cpid=784)
- Hint: Try removing each lifeguard one at a time.
- [Where Am I?](http://usaco.org/index.php?page=viewproblem2&cpid=964)
- Hint: Brute force over all possible substrings.
- (Permutations) [Livestock Lineup](http://usaco.org/index.php?page=viewproblem2&cpid=965)
- [Field Reduction](http://www.usaco.org/index.php?page=viewproblem2&cpid=641)
- Hint: For this problem, you can't do a full complete search; you have to do a reduced search)
- [Back and Forth](http://www.usaco.org/index.php?page=viewproblem2&cpid=857)
- Somewhat harder
<problems-list>
<problem name="Milk Pails" usaco="615" difficulty="Intro" tags={[]}>
Hint: Fix the number of first-type operations you perform.
</problem>
<problem name="Triangles" usaco="1011" difficulty="Easy" tags={[]}>
</problem>
<problem name="Cow Gymnastics" usaco="963" difficulty="Easy" tags={[]}>
Hint: Brute force over all possible pairs.
</problem>
<problem name="Lifeguards" usaco="784" difficulty="Easy" tags={[]}>
Hint: Try removing each lifeguard one at a time.
</problem>
<problem name="Where Am I?" usaco="964" difficulty="Easy" tags={[]}>
Hint: Brute force over all possible substrings.
</problem>
<problem name="Photoshoot" usaco="988" difficulty="Normal" tags={[]}>
Hint: Figure out what exactly you're complete searching.
</problem>
<problem name="Field Reduction" usaco="641" difficulty="Normal" tags={[]}>
Hint: For this problem, you can't do a full complete search; you have to do a reduced search.
</problem>
<problem name="Back & Forth" usaco="857" difficulty="Hard" tags={[]}>
</problem>
<problem name="Livestock Lineup" usaco="965" difficulty="Hard" tags={["permutations"]}>
</problem>
</problems-list>
- USACO Silver
- [Bovine Genomics](http://usaco.org/index.php?page=viewproblem2&cpid=739)
- [Field Reduction](http://usaco.org/index.php?page=viewproblem2&cpid=642)
<problems-list>
<problem name="Bovine Genomics" usaco="739" difficulty="Normal" tags={[]}>
</problem>
<problem name="Field Reduction" usaco="642" difficulty="Normal" tags={[]}>
</problem>
</problems-list>

View file

@ -9,29 +9,30 @@ prerequisites:
## Standard
- [yosupo - Associative Array](https://judge.yosupo.jp/problem/associative_array)
- CSES
- Do roughly the first half of the Sorting and Searching section in the [CSES Problem Set](https://cses.fi/problemset/)
- [Distinct Numbers](https://cses.fi/problemset/task/1621)
- [Concert Tickets](https://cses.fi/problemset/task/1091)
- Uses iterators
- [Sum of Two Values](https://cses.fi/problemset/task/1640)
- Uses iterators
- Can be solved without sets
Do roughly the first half of the Sorting and Searching section in the [CSES Problem Set](https://cses.fi/problemset/).
<problems-list>
<problem name="Associative Array" yosupo="associative_array" difficulty="Intro" tags={[]}>
</problem>
<problem name="Distinct Numbers" cses="1621" difficulty="Intro" tags={[]}>
</problem>
<problem name="Sum of Two Values" cses="1640" difficulty="Intro" tags={[]}>
- Can be solved without sets
</problem>
<problem name="Concert Tickets" cses="1091" difficulty="Easy" tags={["iterators"]}>
</problem>
<problem
name="CSES Towers"
name="Towers"
cses="1073"
difficulty="Easy"
tags={["multiset", "greedy"]} />
<problem
name="CSES Traffic Lights"
name="Traffic Lights"
cses="1163"
difficulty="Normal"
tags={["set"]} />
<problem
name="CSES Room Allocation"
name="Room Allocation"
cses="1164"
difficulty="Normal"
tags={["multiset", "greedy"]} />

View file

@ -26,18 +26,22 @@ Both of these will be covered in Silver. For now, it suffices to learn how graph
## Trees?
## USACO Bronze Problems
(what are you expected to now?)
(what are you expected to know?)
(add some more)
- Tree
- [Factory](http://usaco.org/index.php?page=viewproblem2&cpid=940)
- [Family Tree](http://usaco.org/index.php?page=viewproblem2&cpid=833)
- [Grass Planting (Silver)](http://usaco.org/index.php?page=viewproblem2&cpid=894)
- Permutation
- [Swapity Swap](http://usaco.org/index.php?page=viewproblem2&cpid=1013)
- General Graph
- [The Great Revegetation](http://usaco.org/index.php?page=viewproblem2&cpid=916)
<problems-list>
<problem name="Silver - Grass Planting" usaco="894" difficulty="Easy" tags={["tree"]}>
</problem>
<problem name="The Great Revegetation" usaco="916" difficulty="Hard" tags={[]}>
</problem>
<problem name="Factory" usaco="940" difficulty="Hard" tags={["tree"]}>
</problem>
<problem name="Swapity Swap" usaco="1013" difficulty="Hard" tags={["permutation"]}>
Hint: One option is to keep swapping until the permutation returns to its original state (but can you do better?).
</problem>
<problem name="Family Tree" usaco="833" difficulty="Hard" tags={["tree"]}>
</problem>
</problems-list>

View file

@ -2,9 +2,13 @@
id: rect-geo
title: "Rectangle Geometry"
author: Darren Yao, Michael Cao, Benjamin Qi
description: "\"Geometry\" problems on USACO Bronze are usually quite simple and limited to intersections and unions of squares or rectangles."
description: "Problems on 2D grids"
---
# Geometry
\"Geometry\" problems on USACO Bronze are usually quite simple and limited to intersections and unions of squares or rectangles.
Most only include two or three squares or rectangles, in which case you can simply draw out cases on paper. This should logically lead to a solution.
## Example: [Blocked Billboard](http://usaco.org/index.php?page=viewproblem2&cpid=759)
@ -152,13 +156,14 @@ int main(){
## Problems
- USACO Bronze
- [Fence Painting](http://usaco.org/index.php?page=viewproblem2&cpid=567)
- 1D geometry!!
- [Square Pasture](http://usaco.org/index.php?page=viewproblem2&cpid=663)
- [Blocked Billboard II](http://usaco.org/index.php?page=viewproblem2&cpid=783)
- Also rectangles
- Other
- [CF 587 (Div. 3) C: White Sheet](https://codeforces.com/contest/1216/problem/C)
- See this code (TODO; codeforces is down) for a nice implementation using the Java Rectangle class.
<problems-list>
<problem name="Square Pasture" usaco="663" difficulty="Intro" tags={["rect"]}>
</problem>
<problem name="Blocked Billboard II" usaco="783" difficulty="Easy" tags={["rect"]}>
also rectangles
</problem>
<problem name="Div. 3 C - White Sheet" cf="contest/1216/problem/C" difficulty="Normal" tags={["rect"]}>
See this code (TODO; codeforces is down) for a nice implementation using the Java Rectangle class.
</problem>
</problems-list>

View file

@ -5,20 +5,23 @@ author: Benjamin Qi
description: Introduces the problems of finding level ancestors in a tree and computing the lowest common ancestors.
---
<problems-list>
<problem name="Planet Queries I" cses="1750" difficulty="Easy" tags={["Binary Jumping"]}>
</problem>
<problem name="Company Queries I" cses="1687" difficulty="Easy" tags={["Binary Jumping"]}>
</problem>
<problem name="Company Queries II" cses="1688" difficulty="Easy" tags={["LCA"]}>
</problem>
</problems-list>
## Binary Jumping
- CSES
- [Planet Queries I](https://cses.fi/problemset/task/1750)
- [Company Queries I](https://cses.fi/problemset/task/1687)
## Lowest Common Ancestor
- [CSES Company Queries II](https://cses.fi/problemset/task/1688)
### Tutorial
- CPH 18.1, 18.3
- [cp-algorithms: Lowest Common Ancestor](https://cp-algorithms.com/)
- [cp-algorithms](https://cp-algorithms.com/)
<optional-content title="Improvements">
@ -30,25 +33,28 @@ description: Introduces the problems of finding level ancestors in a tree and co
### Problems
- CSES
- [Distance Queries](https://cses.fi/problemset/task/1135/)
- [Planets Queries II](https://cses.fi/problemset/task/1160)
- USACO
- Gold
- [Cow Land](http://www.usaco.org/index.php?page=viewproblem2&cpid=921)
- LCA + BIT
- Plat
- [Max Flow](http://www.usaco.org/index.php?page=viewproblem2&cpid=576)
- [Disruption](http://www.usaco.org/index.php?page=viewproblem2&cpid=842)
- [Newbarns](http://www.usaco.org/index.php?page=viewproblem2&cpid=817)
- online tree diameter
- Copy of [CF Brain Network "Hard"](https://codeforces.com/contest/690/problem/C3)
- [Tree Boxes](http://www.usaco.org/index.php?page=viewproblem2&cpid=948)
- interactive!!
- [Gathering](http://www.usaco.org/index.php?page=viewproblem2&cpid=866)
- test cases added after contest ...
- [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)
<problems-list>
<problem name="Distance Queries" cses="1135" difficulty="Easy" tags={["LCA"]}>
</problem>
<problem name="Plat - Max Flow" usaco="576" difficulty="Easy" tags={["LCA"]}>
</problem>
<problem name="Root LCA Queries" csa="root-lca-queries" difficulty="Normal" tags={["LCA"]}>
</problem>
<problem name="Planets Queries II" cses="1160" difficulty="Normal" tags={["LCA"]}>
</problem>
<problem name="Plat - Disruption" usaco="842" difficulty="Normal" tags={["LCA"]}>
</problem>
<problem name="Hot & Cold" dmoj="bts17p7" difficulty="Normal" tags={["LCA"]}>
</problem>
<problem name="Plat - Tree Boxes" usaco="948" difficulty="Hard" tags={["LCA"]}>
- interactive!!
</problem>
<problem name="Plat - Newbarns" usaco="817" difficulty="Hard" tags={["Diameter"]}>
Copy of [CF Brain Network "Hard"](https://codeforces.com/contest/690/problem/C3)
</problem>
<problem name="Plat - Gathering" usaco="866" difficulty="Hard" tags={["LCA"]}>
- interactive!!
</problem>
<problem name="Plat - Exercise" usaco="901" difficulty="Very Hard" tags={["LCA"]}>
</problem>
</problems-list>

View file

@ -1,14 +0,0 @@
---
id: ds-gold
title: "Data Structures"
author: Michael Cao
prerequisites:
- Silver - Data Structures
description: "Monotonic stack and sliding window."
---
# Springboards DS
- [Karen & Cards](http://codeforces.com/contest/815/problem/D) [](86)
- Extremely hard, do not attempt (2800 on CF)
(add more once codeforces comes up)

View file

@ -8,10 +8,14 @@ prerequisites:
description: A subset of the edges of a connected, undirected, edge-weighted graph that connects all the vertices to each other of minimum total weight, where no cycles are allowed.
---
## Standard
## Sample
- [Kattis Minimum Spanning Tree](https://open.kattis.com/problems/minspantree)
- same as [CSES Road Reparation](https://cses.fi/problemset/task/1675)
<problems-list>
<problem name="MST" kattis="minspantree" difficulty="Easy" tags={["MST"]}>
</problem>
<problem name="Road Reparation" cses="1675" difficulty="Easy" tags={["MST"]}>
</problem>
</problems-list>
## Tutorial
@ -26,11 +30,16 @@ description: A subset of the edges of a connected, undirected, edge-weighted gra
## USACO Gold Problems
- [Old Silver - SuperBull](http://www.usaco.org/index.php?page=viewproblem2&cpid=531)
- [Walk](http://usaco.org/index.php?page=viewproblem2&cpid=946)
- Prim's is applicable, but the edge weights are special so you don't actually need to use an MST algo ...
- [Fencedin](http://www.usaco.org/index.php?page=viewproblem2&cpid=623)
- also special ...
<problems-list>
<problem name="Old Silver - SuperBull" usaco="531" difficulty="Easy" tags={["MST"]}>
</problem>
<problem name="Walk" usaco="946" difficulty="Easy" tags={["Math", "Prim"]}>
</problem>
<problem name="Fencedin" usaco="623" difficulty="Easy" tags={["MST"]}>
</problem>
<problem name="Plat - Fencedin" usaco="625" difficulty="Normal" tags={["Kruskal"]}>
</problem>
</problems-list>
## Other Problems

View file

@ -46,13 +46,16 @@ Prove that if you instead merge sets that have size equal to the depths of the s
## Problems
- USACO
- [Gold - Favorite Colors](http://www.usaco.org/index.php?page=viewproblem2&cpid=1042)
- merge adjacency lists
- not required to get AC
- [Plat - Disruption](http://www.usaco.org/index.php?page=viewproblem2&cpid=842)
- [Plat - Promotion Counting](http://www.usaco.org/index.php?page=viewproblem2&cpid=696)
(note about indexed set swap)
<problems-list>
<problem name="Distinct Colors" cses="1139" difficulty="Easy" tags={["Merging"]}>
</problem>
<problem name="Lomsat gelral" cf="contest/600/problem/E" difficulty="Normal" tags={["Merging"]}>
</problem>
<problem name="Plat - Disruption" usaco="842" difficulty="Hard" tags={["Merging"]}>
</problem>
<problem name="Plat - Promotion Counting" usaco="696" difficulty="Hard" tags={["Merging"]}>
- merge indexed sets
- Other
- [CSES Distinct Colors](https://cses.fi/problemset/task/1139)
- [CF Lomsat gelral](https://codeforces.com/contest/600/problem/E)
</problem>
</problems-list>

View file

@ -35,6 +35,4 @@ Can try solving some of the BIT questions w/ segtree.
- [USACO Old Gold Marathon](http://www.usaco.org/index.php?page=viewproblem2&cpid=495) (check ...)
- [USACO Plat Balancing](http://www.usaco.org/index.php?page=viewproblem2&cpid=624) (check ...)
- [USACO Plat Nocross](http://www.usaco.org/index.php?page=viewproblem2&cpid=721)
- [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
- [POI Cards](https://szkopul.edu.pl/problemset/problem/qpsk3ygf8MU7D_1Es0oc_xd8/site/?key=statement) [](81)

View file

@ -4,10 +4,21 @@ title: "Point Update Range Sum"
author: Benjamin Qi
prerequisites:
- Silver - Prefix Sums
description: Binary Indexed Trees & Indexed Sets
description: Introducing Binary Indexed Trees & Indexed Sets (C++ only).
---
- [yosupo - Point Add Range Sum](https://judge.yosupo.jp/problem/point_add_range_sum)
## Sample Problems
<problems-list>
<problem name="Point Add Range Sum" yosupo="point_add_range_sum" difficulty="Easy" tags={["PURS"]}>
</problem>
<problem name="Range Sum Queries II" cses="1648" difficulty="Easy" tags={["PURS"]}>
Can also do range XOR queries w/ update.
</problem>
<problem name="Inversion Counting" spoj="INVCNT" difficulty="Easy" tags={["PURS"]}>
Solution notes go here. **Markdown suppported maybe?**
</problem>
</problems-list>
## Binary Indexed Tree
@ -18,18 +29,6 @@ A *Binary Indexed Tree* allows you to perform the following tasks in $O(\log N)$
Aka *Fenwick Tree*.
### Sample Problems
<problems-list>
<problem name="Range Sum Queries II" cses="1648" difficulty="Easy">
Can also do range XOR queries w/ update.
</problem>
<problem name="SPOJ Inversion Counting" link="https://www.spoj.com/problems/INVCNT/" difficulty="Easy">
Solution notes go here. **Markdown suppported maybe?**
</problem>
</problems-list>
### Tutorials
* CPH 9.2, 9.4
@ -53,6 +52,8 @@ In the special case where all elements of the array are either zero or one (whic
See the link for more examples of usage.
<spoiler title="INVCNT with Indexed Set">
```cpp
#include <bits/stdc++.h>
using namespace std;
@ -78,12 +79,12 @@ int main() {
}
```
</spoiler>
Note that if it were not the case that all elements of the input array were distinct, then this code would be incorrect since `Tree<int>` would remove duplicates. Instead, we would use an indexed set of pairs (`Tree<pair<int,int>>`), where the first element of each pair would denote the value while the second would denote the array position.
## Practice Problems
- CSES
<problems-list>
<problem name="List Removals" cses="1749" difficulty="Easy">
easy with indexed set
@ -98,44 +99,39 @@ Note that if it were not the case that all elements of the input array were dist
</problem>
<problem name="Intersection Points" cses="1740" difficulty="Easy">
</problem>
<problem name="Mega Inversions" kattis="megainversions" difficulty="Easy">
also just inversion counting
</problem>
<problem name="Twin Permutations" link="https://www.hackerearth.com/practice/data-structures/advanced-data-structures/fenwick-binary-indexed-trees/practice-problems/algorithm/mancunian-and-twin-permutations-d988930c/description/" difficulty="Easy">
Offline 2D queries can be done with a 1D data structure
</problem>
<problem name="Distinct Values Queries" cses="1734" difficulty="Normal">
Do queries in increasing order of $a$.
</problem>
<problem name="Robot Path" cses="1742" difficulty="Hard">
</problem>
</problems-list>
- USACO Gold
- The first three problems are just variations on inversion counting.
USACO Gold:
- The first three problems are just variations on inversion counting.
<problems-list>
<problem name="Haircut" link="http://www.usaco.org/index.php?page=viewproblem2&cpid=1041" difficulty="Easy">
<problem name="Haircut" usaco="1041" difficulty="Easy">
</problem>
<problem name="Balanced Photo" link="http://www.usaco.org/index.php?page=viewproblem2&cpid=693" difficulty="Easy">
<problem name="Balanced Photo" usaco="693" difficulty="Easy">
</problem>
<problem name="Circle Cross" link="http://www.usaco.org/index.php?page=viewproblem2&cpid=719" difficulty="Easy">
<problem name="Circle Cross" usaco="719" difficulty="Easy">
</problem>
<problem name="Sleepy Cow Sort" link="http://usaco.org/index.php?page=viewproblem2&cpid=898" difficulty="Easy">
<problem name="Sleepy Cow Sort" usaco="898" difficulty="Easy">
All USACO problems (aside from some special exceptions) have only one possible output.
</problem>
<problem name="Out of Sorts" link="http://usaco.org/index.php?page=viewproblem2&cpid=837" difficulty="Hard">
</problem>
</problems-list>
* Other Problems:
<problems-list>
<problem name="Plat - Mincross" usaco="720" difficulty="Easy">
</problem>
<problem name="Mega Inversions" kattis="megainversions" difficulty="Easy">
also just inversion counting
</problem>
<problem name="Silver - Out of Sorts" usaco="834" difficulty="Normal">
- aka [Sorting Steps](https://csacademy.com/contest/round-42/task/sorting-steps/) [](42)
- Of course, this doesn't require anything other than sorting but fast range sum queries may make this easier.
</problem>
<problem name="Twin Permutations" link="https://www.hackerearth.com/practice/data-structures/advanced-data-structures/fenwick-binary-indexed-trees/practice-problems/algorithm/mancunian-and-twin-permutations-d988930c/description/" difficulty="Easy">
Offline 2D queries can be done with a 1D data structure
<problem name="Out of Sorts" usaco="837" difficulty="Hard">
</problem>
</problems-list>

View file

@ -5,7 +5,7 @@ author: Benjamin Qi
prerequisites:
- Silver - More with Maps & Sets
- Silver - Amortized Analysis
description: "Solving USACO Gold - Springboards"
description: "Solving USACO Gold - Springboards."
---
To solve USACO Gold [Springboards](http://www.usaco.org/index.php?page=viewproblem2&cpid=995), we need a data structure that supports operations similar to the following:
@ -43,6 +43,11 @@ ll query(int x) { auto it = m.lb(x);
(easier examples?)
- [CF: Karen & Cards](https://codeforces.com/contest/815/problem/D)
- For each $a$ from $p\to 1$, calculate the number of possible cards with that value of $a$.
- [GP of Korea 19 - Interesting Drug](https://codeforces.com/gym/102059/problem/K)
<problems-list>
<problem name="Karen & Cards" cf="contest/815/problem/D" difficulty="Very Hard" tags={[]}>
- For each $a$ from $p\to 1$, calculate the number of possible cards with that value of $a$.
</problem>
<problem name="GP of Korea 19 - Interesting Drug" cf="gym/102059/problem/K" difficulty="Very Hard" tags={[]}>
- Genfuncs not required but possibly helpful
</problem>
</problems-list>

View file

@ -5,10 +5,18 @@ author: ?
prerequisites:
- Silver - Depth First Search
- Gold - Static Range Queries
- Gold - Point Update Range Sum
description: Subtree updates and queries and another way to compute lowest common ancestors.
---
- [CSES: Subtree Queries](https://cses.fi/problemset/task/1137)
## Sample Problems
<problems-list>
<problem name="Subtree Queries" cses="1137" difficulty="Easy" tags={["Euler-Tree"]}>
</problem>
<problem name="Company Queries II" cses="1688" difficulty="Easy" tags={["LCA"]}>
</problem>
</problems-list>
## Tutorial
@ -17,8 +25,15 @@ description: Subtree updates and queries and another way to compute lowest commo
## Problems
- [CSES: Path Queries](https://cses.fi/problemset/task/1138)
- USACO
- [Gold - Milk Visits](http://www.usaco.org/index.php?page=viewproblem2&cpid=970)
- [Plat - Promotion Counting](http://www.usaco.org/index.php?page=viewproblem2&cpid=696)
- [Plat - Snow-Cow](http://www.usaco.org/index.php?page=viewproblem2&cpid=973)
<problems-list>
<problem name="Path Queries" cses="1138" difficulty="Easy" tags={["Euler-Tree", "PURS"]}>
</problem>
<problem name="Cow Land" usaco="921" difficulty="Normal" tags={["Euler-Tree", "PURS"]}>
</problem>
<problem name="Milk Visits" usaco="970" difficulty="Normal" tags={["Euler-Tree"]}>
</problem>
<problem name="Plat - Promotion Counting" usaco="696" difficulty="Normal" tags={["Euler-Tree", "PURS"]}>
</problem>
<problem name="Plat - Snow-Cow" usaco="973" difficulty="Hard" tags={["Euler-Tree", "PURS"]}>
</problem>
</problems-list>

View file

@ -67,4 +67,5 @@ Note: no lazy propagation in 2D.
### Problems
- [POI Tetris 3D](https://szkopul.edu.pl/problemset/problem/OQjANSOOD_-c38gh8p6g3Gxp/site/?key=statement)
- [IOI 2013 Game](http://wcipeg.com/problem/ioi1323)
- [IOI 2013 Game](http://wcipeg.com/problem/ioi1323)
- good implementation?

View file

@ -14,8 +14,13 @@ description: ?
### Problems
- [Ciel the Commander](https://codeforces.com/problemset/problem/321/C)
- [DMOJ Bob Equilibrium](https://dmoj.ca/problem/dmopc19c7p6)
- tight time limit
- [USACO Plat - At Large](http://www.usaco.org/index.php?page=viewproblem2&cpid=793)
- *very* tricky, requires several observations
<problems-list>
<problem name="Ciel the Commander" cf="problemset/problem/321/C" difficulty="Easy" tags={["Centroid"]}>
</problem>
<problem name="Bob Equilibrium" dmoj="dmopc19c7p6" difficulty="Hard" tags={["Centroid"]}>
- tight time limit
</problem>
<problem name="At Large" usaco="793" difficulty="Very Hard" tags={["Centroid"]}>
- tight time limit
</problem>
</problems-list>

View file

@ -19,8 +19,13 @@ Has not been the solution to any platinum problem, but appeared in old gold and
## Problems
- [CSES Hamiltonian Flights](https://cses.fi/problemset/task/1690)
- [CSES Elevator Rides](https://cses.fi/problemset/task/1653)
<problems-list>
<problem name="Hamiltonian Flights" cses="1690" difficulty="Easy" tags={["Bitmasks"]}>
</problem>
<problem name="Elevator Rides" cses="1653" difficulty="Normal" tags={["LCA"]}>
</problem>
</problems-list>
- [Old Gold - Moovie Moving](http://www.usaco.org/index.php?page=viewproblem2&cpid=515)
- [AC Matching](https://atcoder.jp/contests/dp/tasks/dp_o)
- [CF Square Subsets](https://codeforces.com/contest/895/problem/C)

View file

@ -9,10 +9,17 @@ description: Solving the problem on every contiguous subarray of the original ar
## Problems
* [Gold - 248](http://www.usaco.org/index.php?page=viewproblem2&cpid=647)
* more straightforward
* TC SRM 787 500
* [CSES Empty String](https://cses.fi/problemset/task/1080)
* [CF Zuma](https://codeforces.com/problemset/problem/607/B)
* [Plat - Greedy Pie Eaters](http://www.usaco.org/index.php?page=viewproblem2&cpid=972)
* [Plat - Subsequence Reversal](http://www.usaco.org/index.php?page=viewproblem2&cpid=698)
<problems-list>
<problem name="Gold - 248" usaco="647" difficulty="Easy" tags={["Range DP"]}>
</problem>
<problem name="Empty String" cses="1080" difficulty="Normal" tags={["Range DP"]}>
</problem>
<problem name="Zuma" cf="problemset/problem/607/B" difficulty="Normal" tags={["Range DP"]}>
</problem>
<problem name="Greedy Pie Eaters" usaco="972" difficulty="Normal" tags={["Range DP"]}>
</problem>
<problem name="Subsequence Reversal" usaco="698" difficulty="Normal" tags={["Range DP"]}>
</problem>
</problems-list>
* TC SRM 787 500

View file

@ -32,9 +32,14 @@ description: "?"
## Counting
- USACO Plat
- [Tree Depth](http://www.usaco.org/index.php?page=viewproblem2&cpid=974)
- [Exercise](http://www.usaco.org/index.php?page=viewproblem2&cpid=1045)
<problems-list>
<problem name="Tree Depth" usaco="974" difficulty="Hard" tags={["genfunc"]}>
</problem>
<problem name="Exercise" usaco="1045" difficulty="Hard" tags={["permutation"]}>
- genfuncs not required but possibly helpful
</problem>
</problems-list>
- [zscoder GenFunc Pt 1](https://codeforces.com/blog/entry/77468)
- [zscoder GenFunc Pt 2](https://codeforces.com/blog/entry/77551)

View file

@ -4,6 +4,7 @@ title: "Heavy-Light Decomposition"
author: Benjamin Qi
prerequisites:
- Gold - Euler Tour on Tree
- Platinum - Range Update Range Query
description: Path and subtree updates and queries.
---
@ -17,4 +18,8 @@ description: Path and subtree updates and queries.
### Problems
- [Disrupt](http://www.usaco.org/index.php?page=viewproblem2&cpid=842)
<problems-list>
<problem name="Disrupt" usaco="842" difficulty="Easy" tags={["HLD"]}>
</problem>
</problems-list>

View file

@ -11,9 +11,19 @@ CPH 28.1 (Segment Trees Revisited)
## Lazy Segment Tree
- [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)
- [CSES Area of Rectangles](https://cses.fi/problemset/task/1741)
(problem that's only increment with no sets?)
<problems-list>
<problem name="Range Updates & Sums" cses="1735" difficulty="Easy" tags={["Lazy SegTree"]}>
</problem>
<problem name="Counting Haybales" usaco="578" difficulty="Easy" tags={["Lazy SegTree"]}>
</problem>
<problem name="Old Gold - The Lazy Cow" cses="418" difficulty="Easy" tags={["Lazy SegTree"]}>
</problem>
<problem name="Area of Rectangles" cses="1741" difficulty="Hard" tags={["Lazy SegTree"]}>
- use segment tree that keeps track of minimum and # of minimums
</problem>
</problems-list>
## BIT Revisited
@ -23,7 +33,9 @@ Binary Indexed Trees can support range increments in addition to range sum queri
- [GFG Range Update Range Query](https://www.geeksforgeeks.org/binary-indexed-tree-range-update-range-queries/)
- [My Implementation](https://github.com/bqi343/USACO/blob/master/Implementations/content/data-structures/1D%20Range%20Queries%20(9.2)/BITrange.h)
Example problem:
- [DMOJ Range Update Range Query](https://dmoj.ca/problem/acc3p4)
- [CSES Polynomial Queries](https://cses.fi/problemset/task/1736)
<problems-list>
<problem name="Range Update Range Query" dmoj="acc3p4" difficulty="Normal" tags={["BIT-Range"]}>
</problem>
<problem name="Polynomial Queries" cses="1736" difficulty="Normal" tags={["BIT-Range"]}>
</problem>
</problems-list>

View file

@ -64,8 +64,14 @@ int main() {
```
</spoiler>
### Extension
*Stock Trading (USACO Camp)*: What if your amount of shares can go negative, but you can never have more than $L$ shares or less than $-L$?
## [Potatoes](https://oj.uz/problem/view/LMIO19_bulves)
[Equivalent Problem](https://atcoder.jp/contests/kupc2016/tasks/kupc2016_h)
Let $dif_i=a_i-b_i$. Defining $d_j=\sum_{i=1}^jdif_i$, our goal is to move around the potatoes such that $d_0,d_1,\ldots,d_N$ is a non-decreasing sequence. Moving a potato is equivalent to changing exactly one of the $d_i$ (aside from $d_0,d_N$) by one.
**Slow Solution:** Let $dp[i][j]$ be the minimum cost to determine $d_0,d_1,\ldots,d_i$ such that $d_i\le j$ for each $0\le j\le d_N$. This gives a $O(N\cdot d_N)$ solution.
@ -178,18 +184,20 @@ int main() {
## Problems
- [Wall](https://atcoder.jp/contests/kupc2016/tasks/kupc2016_h)
- same as "Potatoes"
- Stock Trading (Camp)
- extension of "Buy Low Sell High"
- Amount of shares can go negative, but you can never have more than $L$ shares or less than $-L$.
- [Bookface](https://codeforces.com/gym/102576/problem/C)
- [CCDSAP Exam](https://www.codechef.com/problems/CCDSAP)
- basically same as Bookface
- [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)
<problems-list>
<problem name="Bookface" cf="gym/102576/problem/C" difficulty="Easy" tags={["Slope Trick"]}>
</problem>
<problem name="CCDSAP Exam" cc="CCDSAP" difficulty="Easy" tags={["Slope Trick"]}>
</problem>
<problem name="Farm of Monsters" cf="gym/102538/problem/F" difficulty="Hard" tags={["Slope Trick"]}>
</problem>
<problem name="Moving Walkways" cf="contest/1209/problem/H" difficulty="Hard" tags={["Slope Trick"]}>
</problem>
<problem name="April Fools' Problem" cf="contest/802/problem/O" difficulty="Very Hard" tags={["Slope Trick"]}>
- binary search on top of slope trick
- [Conquer the World](https://icpc.kattis.com/problems/conquertheworld)
</problem>
<problem name="Conquer the World" link="https://icpc.kattis.com/problems/conquertheworld" difficulty="Very Hard" tags={["Slope Trick"]}>
- ICPC world finals, 0 solves in contest
- "Potatoes" on tree!!
- "Potatoes" on tree!!
</problem>
</problems-list>

View file

@ -1,40 +1,34 @@
import * as React from "react";
const sources = {
"CC": "https://www.codechef.com/problems/",
"CSA": "https://csacademy.com/contest/archive/task/",
"DMOJ": "https://dmoj.ca/problem/",
"SPOJ": "https://www.spoj.com/problems/",
"YS": "https://judge.yosupo.jp/problem/",
"CF": "https://codeforces.com/",
"USACO": "http://www.usaco.org/index.php?page=viewproblem2&cpid=",
"Kattis": "https://open.kattis.com/problems/",
"CSES": "https://cses.fi/problemset/task/",
};
export class Problem {
public url: string;
constructor(
public source: string,
public name: string,
public url: string,
public id: string,
public starred?: boolean,
public difficulty?: 'Intro' | 'Easy' | 'Normal' | 'Hard' | 'Very Hard',
public source?: string,
public tags?: string[],
public sketch?: string
) {}
public sketch?: string,
) {
if (source in sources) {
this.url = sources[source] + id;
} else {
if (!id.startsWith("http")) {
throw "URL of problem not valid. Did you make a typo in the problem source, or in the URL?"
}
this.url = id;
}
}
}
export namespace Problem {
export class CSES extends Problem {
constructor(
public name: string,
public id: string,
public starred?: boolean,
public difficulty?: 'Intro' | 'Easy' | 'Normal' | 'Hard' | 'Very Hard',
public tags?: string[],
public sketch?: string
) {
super(name, `https://cses.fi/problemset/task/${id}`, starred, difficulty, "CSES", tags, sketch);
}
}
export class USACO extends Problem {
constructor(
public name: string,
public id: string,
public starred?: boolean,
public difficulty?: 'Intro' | 'Easy' | 'Normal' | 'Hard' | 'Very Hard',
public tags?: string[],
public sketch?: string
) {
super(name, `http://www.usaco.org/index.php?page=viewproblem2&cpid=${id}`, starred, difficulty, "USACO", tags, sketch);
}
}
}

View file

@ -69,7 +69,6 @@ const ModuleOrdering = {
},
],
"gold": [
"ds-gold",
"dp",
"intro-nt",
{

View file

@ -16,6 +16,9 @@ export function ProblemsListComponent(props: ProblemsListComponentProps) {
<table className="min-w-full no-markdown">
<thead>
<tr>
<th className="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
Source
</th>
<th className="px-6 py-3 border-b border-gray-200 bg-gray-50" />
<th className="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
Problem Name
@ -23,9 +26,6 @@ export function ProblemsListComponent(props: ProblemsListComponentProps) {
<th className="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
Difficulty
</th>
<th className="px-6 py-3 border-b border-gray-200 bg-gray-50 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
Source
</th>
<th className="px-6 py-3 border-b border-gray-200 bg-gray-50" />
<th className="px-6 py-3 border-b border-gray-200 bg-gray-50" />
</tr>
@ -59,6 +59,9 @@ export function ProblemComponent(props: ProblemComponentProps) {
return (
<tr>
<td className="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500 font-medium">
{problem.source}
</td>
<td className="pl-6 w-6 py-4 whitespace-no-wrap text-sm leading-5 font-medium text-gray-900">
{problem.starred && (
<svg
@ -85,9 +88,6 @@ export function ProblemComponent(props: ProblemComponentProps) {
</span>
)}
</td>
<td className="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-500 font-medium">
{problem.source}
</td>
<td className="px-6 py-4 whitespace-no-wrap text-right text-sm leading-5 font-medium">
{!showTags && (
<a