convert resources

This commit is contained in:
Benjamin Qi 2020-06-27 22:11:09 -04:00
parent 9f2ecc5fa7
commit c241dd6528
22 changed files with 410 additions and 227 deletions

View file

@ -13,79 +13,115 @@ export const metadata = {
bitSam: [
new Problem("CSES", "Forest Queries II", "1739", "Easy", false, ["2D BIT"], "[thecodingwizard's implementation](https://github.com/thecodingwizard/competitive-programming/blob/master/cses/Forest%20Queries%20II.cpp)"),
],
bit: [
new Problem("DMOJ", "Crowded Cities", "bfs17p6", "Normal", false, ["2D Max BIT"], ""),
new Problem("IOI", "Pairs", "https://wcipeg.com/problem/ioi0722", "Normal", false, ["3D BIT"], ""),
],
offSam: [
new Problem("DMOJ", "Soriya's Programming Project", "dmopc19c7p5", "Normal", false, ["2D BIT"], ""),
]
],
off: [
new Problem("Plat", "Friendcross", "722", "Normal", false, ["2D BIT"], ""),
new Problem("Plat", "Mowing the Field", "601", "Normal", false, ["2D BIT"], ""),
],
seg: [
new Problem("POI", "Tetris 3D", "https://szkopul.edu.pl/problemset/problem/OQjANSOOD_-c38gh8p6g3Gxp/site/?key=statement", "Hard", false, ["2D Seg"], ""),
new Problem("ojuz", "IOI 2013 - Game", "IOI13_game", "Hard", false, ["2D Seg"], "Alternatively, use BBST in place of sparse segment tree (see Advanced - Treaps)"),
new Problem("ojuz", "JOI - Golf", "JOI17_golf", "Very Hard", false, ["Seg"], ""),
],
}
};
See [my implementations](https://github.com/bqi343/USACO/tree/master/Implementations/content/data-structures/2D%20Range%20Queries%20(15.2)).
## Static Array Queries
## 2D RMQ
<resources>
<resource source="CF" title="retrograd - Multi-Dimensional RMQ" url="blog/entry/53810" starred></resource>
</resources>
- [Multi-Dimensional RMQ (retrograd)](https://codeforces.com/blog/entry/53810)
- GP of Serbia 2020 B
## 2D BIT
<problems-list problems={metadata.problems.bitSam} />
### Tutorials
### Tutorial
- [GFG 2D BIT](https://www.geeksforgeeks.org/two-dimensional-binary-indexed-tree-or-fenwick-tree/)
- [TopCoder BIT](https://www.topcoder.com/community/competitive-programming/tutorials/binary-indexed-trees/)
<resources>
<resource source="GFG" title="2D BIT" url="two-dimensional-binary-indexed-tree-or-fenwick-tree"></resource>
<resource source="TC" title="Binary Indexed Trees" url="binary-indexed-trees"></resource>
</resources>
### Problems
<problems-list problems={metadata.problems.bit} />
<optional-content title="Range Update and Range Query in Higher Dimensions">
You can extend the 1D BIT solution for range update range query to higher dimensions as well
Lazy propagation on segment trees does not extend to higher dimensions. However, you can extend the 1D BIT solution to solve range increment range sum in higher dimensions as well! See [this paper](https://arxiv.org/pdf/1311.6093.pdf) for details.
- [Paper](https://arxiv.org/pdf/1311.6093.pdf)
- USACO Camp - "Cows Play Global Thermonuclear War" (2D case)
</optional-content>
### Offline
Suppose that you want to update and query with $N\approx 10^5$ points.
- The 2D BITs mentioned above use $O(N^2)$ memory, which is too much.
- Can be reduced to $O(N\log^2N)$ memory with unordered map, but this might also be too much (and too slow).
- If you know the points to be updated beforehand then you can reduce to $O(N\log N)$ memory (and no maps).
- [my 1D offline BIT](https://github.com/bqi343/USACO/blob/master/Implementations/content/data-structures/1D%20Range%20Queries%20(9.2)/BIToff.h)
- [my 2D offline BIT](https://github.com/bqi343/USACO/blob/master/Implementations/content/data-structures/2D%20Range%20Queries%20(15.2)/BIT2DOff%20(15.2).h)
## 2D Offline Sum Queries
<problems-list problems={metadata.problems.offSam} />
The intended complexity is $O(N\log^2 N)$. Two options:
The intended complexity is $O(N\log^2 N)$ with a good constant factor. This requires updating points and querying rectangle sums $N$ times for points with coordinates in the range $[1,N]$. However The 2D BITs mentioned above use $O(N^2)$ memory, which is too much. Since we know all of the updates and queries beforehand, we can reduce the memory usage while maintaining a decent constant factor.
- compressed 2D BIT
- rather difficult to pass within time and memory limits
- Make sure to use `\n` instead of `endl`!
- [thecodingwizard's implementation with Benq's 2d offline bit](https://github.com/thecodingwizard/competitive-programming/blob/master/DMOJ/Soriyas%20Programming%20Project.cpp)
- divide & conquer with a 1D BIT
- mentioned [here](https://robert1003.github.io/2020/01/31/cdq-divide-and-conquer.html).
- [thecodingwizard's (messy) implementation](https://github.com/thecodingwizard/competitive-programming/blob/master/DMOJ/Soriya%20Programming%20Project%201d%20BIT%20cdq%20dnc.cpp) based off of article above
### Idea 1: Use an unordered map instead of a 2D array.
Bad idea ... This gives $O(N\log^2N)$ memory and time and the constant factors for both are terrible.
### Idea 2: Compress the points to be updated so that you only need $O(N\log N)$ memory.
This doesn't require knowing the queries beforehand.
- [my 1D offline BIT](https://github.com/bqi343/USACO/blob/master/Implementations/content/data-structures/1D%20Range%20Queries%20(9.2)/BIToff.h)
- [my 2D offline BIT](https://github.com/bqi343/USACO/blob/master/Implementations/content/data-structures/2D%20Range%20Queries%20(15.2)/BIT2DOff%20(15.2).h)
It's a bit difficult to pass the above problem within the time limit. Make sure to use fast input (and not `endl`)!
- [thecodingwizard's implementation with 2D offline BIT above](https://github.com/thecodingwizard/competitive-programming/blob/master/DMOJ/Soriyas%20Programming%20Project.cpp)
### Idea 3: Use divide & conquer with a 1D BIT
- mentioned in [this article](https://robert1003.github.io/2020/01/31/cdq-divide-and-conquer.html)
- [thecodingwizard's (messy) implementation](https://github.com/thecodingwizard/competitive-programming/blob/master/DMOJ/Soriya%20Programming%20Project%201d%20BIT%20cdq%20dnc.cpp) based off above
### Problems
- [IOI 2007 Pairs](https://wcipeg.com/problem/ioi0722)
- [DMOJ Crowded Cities](https://dmoj.ca/problem/bfs17p6)
- [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)
<problems-list problems={metadata.problems.off} />
## 2D Segment Tree
Note: no lazy propagation in 2D.
Basically a segment tree of (maybe sparse) segment trees (or BBSTs, see "Advanced - Treap").
<info-block title="Pro Tip">
This is **not** the same as [Quadtree](https://en.wikipedia.org/wiki/Quadtree). If the coordinates go up to $C$, then 2D segment tree queries run in $O(\log^2C)$ time each but some queries make Quadtree take $\Theta(C)$ time!
</info-block>
### Short Description
- CSES 28.2 (Sparse Segment Tree), 28.4
- Segment Tree (or BIT) nested inside segment tree
- use 2D offline BIT instead whenever possible (faster, lower memory)
<resources>
<resource source="CPH" title="28.2 (Sparse SegTree), 28.4 (2D)">brief description</resource>
<resource source="USACO" title="Analysis - Mowing the Field" url="http://www.usaco.org/current/data/sol_mowing_platinum_jan16.html">code</resource>
</resources>
### Reducing Memory Usage
Naively, inserting $N$ elements into a sparse segment tree requires $O(N\log C)$, giving a memory bound of $O(N\log^2C)$ on 2D segment tree memory. This is usually too much for $N=10^5$ (although it sufficed for "Mowing the Field" due to the higher memory limit).
To resolve this, reduce the memory usage of sparse segment tree while maintaing the same $O(N\log C)$ insertion time (see the solution for IOI Game below for details).
(implementation)
### Problems
- [POI Tetris 3D](https://szkopul.edu.pl/problemset/problem/OQjANSOOD_-c38gh8p6g3Gxp/site/?key=statement)
- [IOI 2013 Game](http://wcipeg.com/problem/ioi1323)
- good implementation?
Can also try the USACO problems from above.
<problems-list problems={metadata.problems.seg} />

View file

@ -24,6 +24,8 @@ export const metadata = {
new Problem("CSES", "Planets Queries II", "1160", "Normal", false, ["LCA"], ""),
new Problem("Plat", "Disruption", "842", "Normal", false, ["LCA"], ""),
new Problem("DMOJ", "Hot & Cold", "bts17p7", "Normal", false, ["LCA"], ""),
new Problem("TOKI", "Functional Constraint", "https://tlx.toki.id/contests/troc-12-div-1/problems/D", "Hard", false, ["LCA"], ""),
new Problem("TOKI", "Graph & Destination", "https://tlx.toki.id/contests/troc-13-div-1/problems/E", "Hard", false, ["LCA"], ""),
new Problem("Plat", "Tree Boxes", "948", "Hard", false, ["LCA"], "interactive!!"),
new Problem("Plat", "Newbarns", "817", "Hard", false, ["Diameter"], "Copy of CF Brain Network \"Hard\": https://codeforces.com/contest/690/problem/C3"),
new Problem("Plat", "Gathering", "866", "Hard", false, ["LCA"], "interactive!!"),

View file

@ -22,8 +22,6 @@ export const metadata = {
}
};
(another DMOJ prob?)
### Tutorial
<resources>

View file

@ -14,10 +14,18 @@ import { Problem } from "../models";
export const metadata = {
problems: {
general: [
new Problem("CSES", "Hamiltonian Flights", "1690", "Easy", false, ["Bitmasks"], ""),
new Problem("AC", "Matching", "https://atcoder.jp/contests/dp/tasks/dp_o?lang=en", "Intro", false, ["Bitmasks"], ""),
new Problem("CSES", "Hamiltonian Flights", "1690", "Intro", false, ["Bitmasks"], ""),
new Problem("CF", "Square Subsets", "contest/895/problem/C", "Easy", false, [], ""),
new Problem("Kattis", "Cat & Mice", "catandmice", "Normal", false, ["Bitmasks", "Geometry"], ""),
new Problem("Old Gold", "Moovie Mooving", "515", "Normal", false,[ "Bitmasks"], ""),
new Problem("CSES", "Elevator Rides", "1653", "Normal", false, ["Bitmasks"], ""),
new Problem("ojuz", "IZhO Bank", "IZhO14_bank", "Normal", false, ["Bitmasks"], ""),
new Problem("YS", "Max Indep Set", "maximum_independent_set", "Hard", false, ["Bitmasks", "Meet in Middle"], ""),
new Problem("YS", "Max Indep Set", "maximum_independent_set", "Normal", false, ["Bitmasks", "Meet in Middle"], ""),
],
broken: [
new Problem("CF", "Guards in the Storehouse", "problemset/problem/845/F", "Normal", false, [], ""),
new Problem("Plat", "Compound Escape", "949", "Very Hard", false, [], ""),
],
}
};
@ -30,18 +38,23 @@ Although this has not been the solution to any platinum problem, you can frequen
## Tutorial
- [PAPS 9.4](https://www.csc.kth.se/~jsannemo/slask/main.pdf)
- CPH 10 (Bit manipulation), 19.2 (Hamiltonian Paths)
- [Dynamic Programming Over Subsets (Codeforces)](https://codeforces.com/blog/entry/337)
- [Dynamic Programming and Bit Masking (HackerEarth)](https://www.hackerearth.com/practice/algorithms/dynamic-programming/bit-masking/tutorial/)
<resources>
<resource source="PAPS" title="9.4"> </resource>
<resource source="CPH" title="10 (Bit Manipulation), 19.2 (Hamiltonian Paths)"> </resource>
<resource source="CF" title="DP Over Subsets" url="blog/entry/337"> </resource>
<resource source="HE" title="DP and Bit Masking" url="https://www.hackerearth.com/practice/algorithms/dynamic-programming/bit-masking/tutorial/"> </resource>
</resources>
## Problems
<problems-list problems={metadata.problems.general} />
- [Old Gold - Moovie Mooving](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)
- [CF Guards in the Storehouse](https://codeforces.com/problemset/problem/845/F)
- [Kattis Cat & Mice](https://open.kattis.com/problems/catandmice) [](66)
- plus a bit of geometry
## DP on Broken Profile
<resources>
<resource source="cp-algo" title="DP on Broken Profile" url="dynamic_programming/profile-dynamics.html"> </resource>
</resources>
(fill in? more probs?)
<problems-list problems={metadata.problems.broken} />

View file

@ -22,8 +22,10 @@ export const metadata = {
}
};
## Tutorial
## Problems
<problems-list problems={metadata.problems.general} />
* TC SRM 787 500
* TC SRM 787 500

View file

@ -13,7 +13,7 @@ import { Problem } from "../models";
export const metadata = {
problems: {
e1: [
new Problem("DMOJ", "Rainbow Gold", "apio17p1", "Hard", false, [],""),
new Problem("DMOJ", "Land of the Rainbow Gold", "apio17p1", "Hard", false, [],""),
],
e2: [
new Problem("Plat", "Valleys", "950", "Hard", false, [], ""),
@ -28,10 +28,10 @@ export const metadata = {
<problems-list problems={metadata.problems.e1} />
Land of Rainbow Gold
## Example 2
<problems-list problems={metadata.problems.e2} />
Extension:
<problems-list problems={metadata.problems.other} />

View file

@ -10,6 +10,9 @@ frequency: 1
Has not been the solution to any platinum problem, but appeared in old gold.
- [Fast Flow](http://www.spoj.com/problems/FASTFLOW/) [](107)
- [YS - Bipartite Matching](https://judge.yosupo.jp/problem/bipartitematching)
## Maximum Flow
- [CSES Download Speed](https://cses.fi/problemset/task/1694)
@ -24,7 +27,20 @@ Has not been the solution to any platinum problem, but appeared in old gold.
- Min-Cut Max-Flow Theorem
- [Closure Problem](https://en.wikipedia.org/wiki/Closure_problem)
## Bipartite Matching
- [School Dance](https://cses.fi/problemset/task/1696)
- matching
Old Gold - Cow Steepchase http://www.usaco.org/index.php?page=viewproblem2&cpid=93
## Min-Cut Max Flow
- [Coin Grid](https://cses.fi/problemset/task/1709)
Dilworth stuff
https://maps20.kattis.com/problems/thewrathofkahn
### Dinic's Algorithm
@ -42,16 +58,11 @@ However, the standard implementation of Dinic's is (almost) always fast enough.
### Problems
- CSES
- [School Dance](https://cses.fi/problemset/task/1696)
- [Coin Grid](https://cses.fi/problemset/task/1709)
- [Distinct Routes](https://cses.fi/problemset/task/1711)
- Other
- [Goods Transportation](http://codeforces.com/problemset/problem/724/E) [](52)
- [ARC 85 MUL](http://arc085.contest.atcoder.jp/tasks/arc085_c) [](67)
- [Fashion](https://csacademy.com/contest/rmi-2017-day-1/task/fashion/statement/) [](95)
- [Fast Flow](http://www.spoj.com/problems/FASTFLOW/) [](107)
- [Card Game](http://codeforces.com/problemset/problem/808/F) [](135)
- [CSES Distinct Routes](https://cses.fi/problemset/task/1711)
- [Goods Transportation](http://codeforces.com/problemset/problem/724/E) [](52)
- [ARC 85 MUL](http://arc085.contest.atcoder.jp/tasks/arc085_c) [](67)
- [Fashion](https://csacademy.com/contest/rmi-2017-day-1/task/fashion/statement/) [](95)
- [Card Game](http://codeforces.com/problemset/problem/808/F) [](135)
## Flow with Lower Bounds

View file

@ -27,8 +27,6 @@ You should know basic operations like cross product and dot product. For platinu
- Template Testing
- [yosupo: Sort Points by Arg](https://judge.yosupo.jp/problem/sort_points_by_argument)
- [Kattis Segment Distance](https://open.kattis.com/problems/segmentdistance)
- [Kattis Segment Intersection](https://open.kattis.com/problems/segmentintersection)
- [Kattis Point in Polygon](https://open.kattis.com/problems/pointinpolygon)
- [Kattis Polygon Area](https://open.kattis.com/problems/polygonarea)
- [Kattis Max Collinear](https://open.kattis.com/problems/maxcolinear)

View file

@ -52,17 +52,19 @@ export const metadata = {
## Rotating Caliphers
<problems-list problems={metadata.problems.sample2} />
diameter of point set:
- [CF Comment](https://codeforces.com/blog/entry/46162)
<resources>
<resource source="CF" title="Rotating calipers technique and applications" url="blog/entry/46162"> </resource>
</resources>
<problems-list problems={metadata.problems.rotating} />
## Convex Hull Trick
- [CF Tutorial](https://codeforces.com/blog/entry/63823)
<resources>
<resource source="cp-algo" title="Convex Hull Trick" url="geometry/convex_hull_trick.html" starred> </resource>
<resource source="CF" title="Convex Hull Trick - Geo Being Useful" url="blog/entry/63823" starred> </resource>
</resources>
<problems-list problems={metadata.problems.cht} />

View file

@ -13,34 +13,39 @@ import { Problem } from "../models";
export const metadata = {
problems: {
sample: [
new Problem("YS", "Line Add Get Min", "line_add_get_min", "Easy", false, [], ""),
new Problem("YS", "Line Add Get Min", "line_add_get_min", "Normal", false, [], ""),
],
half: [
new Problem("Kattis", "Marshland Rescues", "https://maps19.kattis.com/problems/marshlandrescues", "Normal", false, [], ""),
],
probs: [
new Problem("YS", "Line Add Get Min", "segment_add_get_min", "Normal", false, [], ""),
new Problem("YS", "Segment Add Get Min", "segment_add_get_min", "Normal", false, [], ""),
new Problem("CSA", "Building Bridges", "building-bridges", "Normal", false, [], ""),
new Problem("Old Gold", "Fencing the Herd", "534", "Normal", false, [], ""),
new Problem("Old Gold", "Fencing the Herd", "534", "Hard", false, [], ""),
new Problem("TOKI", "Mall & Transportation", "https://tlx.toki.id/contests/troc-13-div-1/problems/D", "Hard", false, [], ""),
]
}
};
## Half-Plane Intersection
- [Blogewoosh (Half-Plane Intersection w/ Ternary Search)](https://codeforces.com/blog/entry/61710)
- [Petr (Linear Half-Plane Intersection)](https://petr-mitrichev.blogspot.com/2016/07/a-half-plane-week.html)
<resources>
<resource source="CF" title="Blogewoosh - Half-Plane Intersection w/ Ternary Search" url="blog/entry/61710" starred></resource>
<resource source="Petr" title="Linear Half-Plane Intersection" url="https://petr-mitrichev.blogspot.com/2016/07/a-half-plane-week.html" starred>expected linear!</resource>
</resources>
<problems-list problems={metadata.problems.half} />
## LineContainer
<problems-list problems={metadata.problems.sample} />
- [KACTL LineContainer](https://github.com/kth-competitive-programming/kactl/blob/master/content/data-structures/LineContainer.h)
- [Lichao Segment Tree](http://codeforces.com/blog/entry/51275?#comment-351510)
- [retrograd Half-Plane Set](https://codeforces.com/blog/entry/61710?#comment-457662)
<resources>
<resource source="KACTL" title="LineContainer" url="https://github.com/kth-competitive-programming/kactl/blob/master/content/data-structures/LineContainer.h" starred>code</resource>
<resource source="cp-algo" title="Lichao Tree" url="geometry/convex_hull_trick.html" starred> </resource>
<resource source="CF" title="retrograd - Half-Plane Set" url="blog/entry/61710?#comment-457662">code</resource>
</resources>
## Problems
<problems-list problems={metadata.problems.probs} />
(add ICPC probs?)
TOKI problem
<problems-list problems={metadata.problems.probs} />

View file

@ -15,12 +15,14 @@ export const metadata = {
new Problem("Plat", "Tall Barn", "697", "Easy", false, [], ""),
],
probs: [
new Problem("CF","New Year & Handle Change", "contest/1279/problem/F", "Normal", false, [], ""),
new Problem("Kattis", "Blazing New Trails", "blazingnewtrails", "Normal", false, [], ""),
new Problem("ojuz", "Aliens", "IOI16_aliens", "Hard", false, [], ""),
]
}
};
aka just binary search on derivative
adding lambda\*smth
<problems-list problems={metadata.problems.sample} />
@ -32,12 +34,4 @@ aka just binary search on derivative
## Problems
<problems-list problems={metadata.problems.probs} />
Edu CF prob
CSA prob
MST K White
300iq contest 2 insane prob(s)
<problems-list problems={metadata.problems.probs} />

View file

@ -4,6 +4,7 @@ title: "Small-To-Large Merging"
author: Michael Cao
prerequisites:
- Silver - Depth First Search
- Gold - Point Update Range Sum
description: "?"
frequency: 1
---
@ -12,12 +13,14 @@ import { Problem } from "../models";
export const metadata = {
problems: {
general: [
sam: [
new Problem("CSES", "Distinct Colors", "1139", "Intro", false, ["Merging"]),
],
general: [
new Problem("CF", "Lomsat gelral", "contest/600/problem/E", "Normal", false, ["Merging"]),
new Problem("Plat", "Promotion Counting", "696", "Normal", false, ["Merging", "Indexed Set"], ""),
new Problem("Gold", "Favorite Colors", "1042", "Hard", false, ["DSU"], "Small to large merging is mentioned in the editorial, but we were unable to break solutions that just merged naively."),
new Problem("Plat", "Disruption", "842", "Hard", false, ["Merging"]),
new Problem("Plat", "Promotion Counting", "696", "Hard", false, ["Merging"], "Merge indexed sets"),
]
}
};
@ -31,31 +34,29 @@ export const metadata = {
<resource source="CF" title="tuwuna - Explaining DSU on Trees" url="blog/entry/67696"></resource>
</resources>
# Merging Sets
## Merging Sets
Let's consider a tree, rooted at node $1$, where each node has a color (see [CSES Distinct Colors](https://cses.fi/problemset/task/1139)).
<problems-list problems={metadata.problems.sam} />
Let's consider a tree rooted at node $1$, where each node has a color.
For each node, let's store a set containing only that node, and we want to merge the sets in the nodes subtree together such that each node has a set consisting of all colors in the nodes subtree. Doing this allows us to solve a variety of problems, such as query the number of distinct colors in each subtree. Doing this naively, however, yields a runtime complexity of $O(N^2)$.
However, with just a few lines of code, we can significantly speed this up.
However, with just a few lines of code, we can significantly speed this up. Note that [swap](http://www.cplusplus.com/reference/utility/swap/) exchanges two sets in $O(1)$ time.
```cpp
if(a.size() < b.size()){ //for two sets a and b
swap(a,b);
}
```
In other words, by merging the smaller set into the larger one, the runtime complexity becomes $O(N\log N).$
```
<details>
<summary> Proof </summary>
By merging the smaller set into the larger one, the runtime complexity becomes $O(N\log N).$ ?? (Ben - this is false)
### Proof
When merging two sets, you move from the smaller set to the larger set. If the size of the smaller set is $X$, then the size of the resulting set is at least $2X$. Thus, an element that has been moved $Y$ times will be in a set of size $2^Y$, and since the maximum size of a set is $N$ (the root), each element will be moved at most $O(\log N$) times leading to a total complexity of $O(N\log N)$.
</details>
Additionally, a set doesn't have to be an `std::set`. Many data structures can be merged, such as `std::map` or even adjacency lists.
<details>
<summary> Full Code </summary>
<spoiler title="Full Code">
```cpp
#include <bits/stdc++.h>
@ -100,7 +101,11 @@ int main() {
}
```
</details>
</spoiler>
## Generalizing
A set doesn't have to be an `std::set`. Many data structures can be merged, such as `std::map` or `std:unordered_map`. However, `std::swap` doesn't necessarily work in $O(1)$ time; for example, swapping two [arrays](http://www.cplusplus.com/reference/array/array/swap/) takes time linear in the sum of the sizes of the arrays, and the same goes for indexed sets. For two indexed sets `a` and `b` we can use `a.swap(b)` in place of `swap(a,b)` (documentation?).
<info-block title="Challenge">
@ -112,6 +117,4 @@ Prove that if you instead merge sets that have size equal to the depths of the s
## Problems
(note about .swap() vs swap)
<problems-list problems={metadata.problems.general} />

View file

@ -6,59 +6,66 @@ description: Once you've reached Platinum, it may be helpful to practice with pr
---
> Hello, Which online judge should I practice more to do well in **IOI** ?
> the closest OJ for IOI style?
> Do you have any magic problems sets to suggest?
## National
## [USACO](http://www.usaco.org/)
See [here](https://ioinformatics.org/page/members/7) for additional links. The [OI Checklist](https://oichecklist.pythonanywhere.com/) is a great way to track your progress. :)
* Older Problems
* [TJ website](http://tjsct.wikidot.com/usaco/)
* [Korean website to submit ...](https://www.acmicpc.net/category/106)
* [USACO Training](http://train.usaco.org/usacogate)
* not particularly beginner-friendly but still helpful
* somewhat outdated in the sense that it lacks topics which are now quite common (ex. segment tree)
* if you're unsure about whether it will be useful, you might as well try it and see where you get stuck :P
* personally, I did the first five chapters in one summer (though I had to look up some hints ...)
* [article :o](https://www.usenix.org/legacy/bodinfo/bod/bodmarch10/future.pdf)
## [oj.uz](https://oj.uz/)
The [OI Checklist](https://oichecklist.pythonanywhere.com/) is a great way to track your progress. :)
<resources>
<resource source="IZhO" title="International Zhautykov Olympiad (Kazakhstan)" url="https://izho.kz/"></resource>
<resource source="APIO" title="Asia-Pacific Informatics Olympiad" url="http://apio-olympiad.org/"></resource>
<resource source="COCI" title="Croatian Open Contests in Informatics" url="http://hsin.hr/coci/">not full feedback ...</resource>
<resource source="JOI" title="Japanese Olympiad in Informatics" url="https://www.ioi-jp.org/"></resource>
<resource source="LMIO" title="Lithuanian Olympiad in Informatics" url="http://online.lmio.lt/"></resource>
<resource source="InfO(1) Cup" title="InfO(1) Cup" url="http://info1cup.com/"></resource>
</resources>
## [IOI](https://ioinformatics.org/)
Can submit on more recent problems on oj.uz. Also see the following:
- [Yandex](https://contest.yandex.com/ioi/)
- [WCIPEG](https://wcipeg.com/problems/cat%3Dioi%2Cshow%3D50)
- [DMOJ](https://dmoj.ca/problems/?category=5)
Misc:
- [IOI Syllabus](https://people.ksp.sk/~misof/ioi-syllabus/)
- [kostka - List of 2019 IOI Participants](http://weaselcrow.com/pro/cf/ioi/19/)
## [CSES](https://cses.fi/)
<resources>
<resource source="BOI" title="Baltic Olympiad in Informatics" url="http://www.boi2017.org/">2017 website</resource>
<resource source="CEOI" title="Central European Olympiad in Informatics" url="http://ceoi.inf.elte.hu/"> </resource>
</resources>
## Other
See the [IOI members page](https://ioinformatics.org/page/members/7) for additional links.
* [USA](http://www.usaco.org/)
* Format
* Bronze, Silver, Gold, Platinum Divisions
* 3 problems, 4 hrs
* [Very Old Gold Probs](http://tjsct.wikidot.com/usaco/)
* [USACO Training](http://train.usaco.org/usacogate)
* not particularly beginner-friendly but still helpful
* somewhat outdated in the sense that it lacks topics which are now quite common (ex. segment tree)
* if you're unsure about whether it will be useful, you might as well try it and see where you get stuck :P
* personally, I did the first five chapters in one summer (though I had to look up some hints ...)
* [article :o](https://www.usenix.org/legacy/bodinfo/bod/bodmarch10/future.pdf)
* [Japan](https://www.ioi-jp.org/)
* [Open Contests](https://contests.ioi-jp.org/)
* see [oj.uz](https://oj.uz/problems/source/45)
* [Poland](https://szkopul.edu.pl/portal/)
* [Solutions (in Polish)](https://www.oi.edu.pl/l/40/)
* [Canada](https://cemc.math.uwaterloo.ca/contests/computing.html)
* [WCIPEG](https://wcipeg.com/problems/cat%3Dccc%2Cshow%3D50)
* [DMOJ](https://dmoj.ca/problems/?category=24)
* [Croatia](http://hsin.hr/coci/)
* not full feedback
* [Indonesia](https://competition.ia-toki.org/contests)
* monthly
* [Philippines](https://noi.ph/past-problems/)
* Other
* [China (WCIPEG)](https://wcipeg.com/problems/cat%3Dnoi%2Cshow%3D50)
* [Lithuania](http://online.lmio.lt/)
* [Australia](https://orac.amt.edu.au/)
* [Italy](https://training.olinfo.it/#/overview)
## International
* IOI
* Online Judges
* [Yandex](https://contest.yandex.com/ioi/)
* [WCIPEG](https://wcipeg.com/problems/cat%3Dioi%2Cshow%3D50)
* [DMOJ](https://dmoj.ca/problems/?category=5)
* [oj.uz](https://oj.uz/problems/source/22)
* Misc
* [List of 2017 IOI Participants](http://weaselcrow.com/pro/cf/ioi2017/)
* [IOI 2018 Syllabus](https://people.ksp.sk/~misof/ioi-syllabus/ioi-syllabus.pdf)
* [Baltic](http://www.boi2017.org/) (BOI)
* [Central European](http://ceoi.inf.elte.hu/) (CEOI)
* submit BOI / CEOI at [CSES](https://cses.fi/)
* [Balkan](http://boi2018.ro/home)
* [International Zhautykov](https://oj.uz/problems/source/24) (IZhO)
* [Asia-Pacific](http://apio-olympiad.org/) (APIO)
* [Indonesia](https://competition.ia-toki.org/contests)
* [Australia](https://orac.amt.edu.au/)
* [Italy](https://training.olinfo.it/#/overview)
* [International Informatics Olympiad in Teams](http://ioit.altervista.org/2018-teams-and-contests-.html) (IOIT)
* [InfO(1) cup](http://info1cup.com/)
* [Balkan Olympiad in Informatics](https://boi2019.epy.gr/) (2019 website)

View file

@ -5,38 +5,52 @@ author: Benjamin Qi
prerequisites:
- Gold - Shortest Paths with Non-Negative Edge Weights
description: Applications of Bellman-Ford.
frequency: 1
frequency: 0
---
- Hasn't appeared in recent USACO Gold as far as I know.
- 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).
import { Problem } from "../models";
export const metadata = {
problems: {
linear: [
new Problem("ojuz", "Restore Array", "RMI19_restore", "Normal", false, [], "similar to [Art](https://codeforces.com/gym/102394/problem/A)"),
],
}
};
### Tutorial
- CPH 13.1
- [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/)
<resources title="SSSP Negative">
<resource source="CPH" title="13.1"></resource>
<resource source="cp-algo" title="Bellman-Ford" url="graph/bellman_ford.html"></resource>
<resource source="cp-algo" title="Finding Negative Cycle" url="finding-negative-cycle-in-graph.html"></resource>
<resource source="TC" title="Intro to Graphs Section 3" url="introduction-to-graphs-and-their-data-structures-section-3/"></resource>
</resources>
Can also 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).
(code)?
### Problems
- General
- [SPOJ Arbitrage](https://www.spoj.com/problems/ARBITRAG/)
- [Kattis APSP (with negative weights)](https://open.kattis.com/problems/allpairspath)
- [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)
- [SPOJ Arbitrage](https://www.spoj.com/problems/ARBITRAG/)
- [Kattis SSSP Negative](https://open.kattis.com/problems/shortestpath3)
- [Kattis APSP (with negative weights)](https://open.kattis.com/problems/allpairspath)
- [CSES (Negative) Cycle Finding](https://cses.fi/problemset/task/1197)
- [CSES High Score](https://cses.fi/problemset/task/1673)
## Simple Linear Programming
You can also use shortest path algorithms to solve the following problem (a very simple [linear program](https://en.wikipedia.org/wiki/Linear_programming)).
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)
<resources>
<resource source="MIT" title="Slides from Intro to Algorithms" url="https://www.cs.rit.edu/~spr/COURSES/ALG/MIT/lec18.pdf">Linear Programming Trick</resource>
</resources>
**Example:** Timeline (USACO Camp)
- equivalent to [Timeline (Gold)](http://www.usaco.org/index.php?page=viewproblem2&cpid=1017) except $N,C\le 5000$ and negative values of $x$ are possible.
### Problems
- [Restore Array](https://oj.uz/problem/view/RMI19_restore)
- [Art](https://codeforces.com/gym/102394/problem/A) (basically same as above)
- Timeline (Camp)
- equivalent to [Timeline (Gold)](http://www.usaco.org/index.php?page=viewproblem2&cpid=1017) except $N,C\le 5000$ and negative values of $x$ are possible.

View file

@ -72,4 +72,3 @@ Of course, you can do this in $O(\log^2N)$ time with a max segment tree and bina
### Problems
<problems-list problems={metadata.problems.wavelet} />

View file

@ -8,12 +8,37 @@ description: Knuth-Morris-Pratt and Z Algorithms (and a few more related topics)
frequency: 1
---
export const metadata = {
problems: {
sample: [
new Problem("YS", "Set XOR-Min", "set_xor_min", "Normal", false, [], ""),
],
}
};
<problems-list problems={metadata.problems.sample} />
## General
## Tries
<resources>
<resource source="CPH" title="26.2"></resource>
<resource source="CF" title="Algorithm Gym" url="blog/entry/15729"></resource>
</resources>
## General Resources
- [CPC.11](https://github.com/SuprDewd/T-414-AFLV/tree/master/11_strings)
- [CP-Algorithms String Processing: Fundamentals](https://cp-algorithms.com/)
## Z, KMP
## KMP
https://cp-algorithms.com/string/prefix-function.html
## Z Algorithm
https://cp-algorithms.com/string/z-function.html
- [yosupo - Z](https://judge.yosupo.jp/problem/zalgorithm)
- Tutorial
@ -37,7 +62,15 @@ frequency: 1
- [adamant](http://codeforces.com/blog/entry/14854)
- [GeeksForGeeks](http://www.geeksforgeeks.org/aho-corasick-algorithm-pattern-searching/)
## Palindromic Tree (Intro)
https://cp-algorithms.com/string/aho_corasick.html
## Palindromes
### Manacher
https://cp-algorithms.com/string/manacher.html
### Introduction to Palindromic Tree
[Palindromic Tree](http://codeforces.com/blog/entry/13959)

View file

@ -2,19 +2,75 @@
id: suffix-array
title: "Suffix Array"
author: Benjamin Qi
description: Sorting Suffixes of a String
description: "Quickly Sorting Suffixes of a String (and Applications)"
prerequisites:
- Gold - Hashing
frequency: 1
---
https://judge.yosupo.jp/problem/suffixarray
https://judge.yosupo.jp/problem/number_of_substrings
import { Problem } from "../models";
- [USACO Plat - Standing Out from the Herd](http://www.usaco.org/index.php?page=viewproblem2&cpid=768)
export const metadata = {
problems: {
sample: [
new Problem("YS", "Suffix Array", "suffixarray", "Easy", false, [], ""),
],
lcpSam: [
new Problem("YS", "# of Substrings", "number_of_substrings", "Easy", false, [], ""),
],
lcp: [
new Problem("Plat", "Standing Out from the Herd", "768", "Normal", false, [], ""),
new Problem("CF", "Two Prefixes", "contest/1090/problem/J", "Hard", false, [], ""),
],
burSam: [
new Problem("CSES", "String Transform", "1113", "Easy", false, [], ""),
],
runSam: [
new Problem("YS", "Run Enumerate", "runenumerate", "Hard", false, [], ""),
]
}
};
<resources>
<resource source="CF" title="Suffix Array" url="edu/course/2/lesson/2" starred>Videos & Practice Problems</resource>
<resource source="cp-algo" title="Suffix Array - Definition & Construction" url="suffix-array.html" starred></resource>
</resources>
## Suffix Array
<problems-list problems={metadata.problems.sample} />
(recommend that you also test against brute force for many small strings)
(impl)
## LCP Array
<problems-list problems={metadata.problems.lcpSam} />
Quickly compute longest common prefix of two suffixes.
(impl)
<problems-list problems={metadata.problems.lcp} />
## Inverse Burrows-Wheeler
<resources>
<resource source="GFG" title="Inverting Burrows-Wheeler Transform" url="inverting-burrows-wheeler-transform">could be simpler?</resource>
</resources>
CSES Guide?
<problems-list problems={metadata.problems.burSam} />
## Run Enumerate
https://judge.yosupo.jp/problem/runenumerate
<resources>
<resource source="cp-algo" title="Finding repetitions" url="main_lorentz.html">could be simpler?</resource>
</resources>
(describe how to do easily w/ suffix array)
<problems-list problems={metadata.problems.runSam} />

View file

@ -3,32 +3,59 @@ id: sweep-line
title: "Sweep Line"
author: Benjamin Qi
description: Introduction to line sweep.
prerequisites:
- "Platinum - Geometry Primitives"
frequency: 1
---
## Sweep Line
import { Problem } from "../models";
export const metadata = {
problems: {
closest: [
new Problem("Kattis", "Closest Pair", "closestpair2", "Normal", false, [], ""),
],
seg: [
new Problem("Kattis", "Segment Intersection", "segmentintersection", "Intro", false, [], ""),
new Problem("Kattis", "Segment Distance", "segmentdistance", "Intro", false, [], ""),
new Problem("Silver", "Cow Steepchase II", "943", "Normal", false, [], ":|"),
],
manSam: [
new Problem("Kattis", "Grid MST", "gridmst", "Normal", false, [], ""),
],
man: [
new Problem("CSA", "The Sprawl", "the-sprawl", "Hard", false, [], ""),
]
}
};
(what's line sweep?)
<resources>
<resource source="CPH" title="30.1, 30.2 - Sweep Line Algorithms"></resource>
<resource source="TC" title="Line Sweep Algorithms" url="line-sweep-algorithms"></resource>
</resources>
### 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)
<problems-list problems={metadata.problems.closest} />
(explanation? KACTL?)
## Line Segment Intersection
- [Cow Steepchase II (Silver)](http://www.usaco.org/index.php?page=viewproblem2&cpid=943)
- :|
<problems-list problems={metadata.problems.seg} />
(explanation?)
## Manhattan MST
https://open.kattis.com/problems/gridmst
<problems-list problems={metadata.problems.manSam} />
CSA 84 The Sprawl
(KACTL code)
explanation? topcoder prob has
<problems-list problems={metadata.problems.man} />
TC 760 ComponentsForever

View file

@ -1,22 +0,0 @@
---
id: tries
title: "Tries"
author: Benjamin Qi
description: ?
frequency: 1
---
import { Problem } from "../models";
export const metadata = {
problems: {
sample: [
new Problem("YS", "Set XOR-Min", "set_xor_min", "Normal", false, [], ""),
],
}
};
<problems-list problems={metadata.problems.sample} />
- CPH 26.2
- [Algorithm Gym](http://codeforces.com/blog/entry/15729)

View file

@ -49,6 +49,8 @@ export const metadata = {
(Implementation?)
- [Euler Tour Tree](https://codeforces.com/blog/entry/18369)
## Link Cut Tree - Paths
<problems-list problems={metadata.problems.lctSam} />

View file

@ -18,19 +18,23 @@ Historically restricted to USACO Camp (aside from the exception below).
- [PPT](https://docs.google.com/presentation/d/14xgtdDWnIBwmJRAuIdZ8FvLZcX9uRxnNoGOGAQRDIvc/edit?usp=sharing)
- Samuel Hsiang Guide (see resources)
### Other
- [Euler Tour Tree](https://codeforces.com/blog/entry/18369)
- [Merging Segment Trees](https://codeforces.com/blog/entry/49446)
## Problems
- [Old Gold - Airplane Boarding](http://www.usaco.org/index.php?page=viewproblem2&cpid=402)
- [Strings](https://csacademy.com/contest/archive/task/strings/) [](181)
- [Points & Distances](https://www.hackerearth.com/problem/algorithm/septembereasy-points-and-distances-d30d0e6b/description/) [](185)
- [Tree Rotations 2](https://szkopul.edu.pl/problemset/problem/b0BM0al2crQBt6zovEtJfOc6/site/?key=statement) [](193)
IOI 2013 Game - https://oj.uz/submission/242393
A2OJ: https://a2oj.com/category?ID=14
?
?
## Splitting & Merging Segment Trees
### Tutorial
- [Merging Segment Trees](https://codeforces.com/blog/entry/49446)
- [Tree Rotations 2](https://szkopul.edu.pl/problemset/problem/b0BM0al2crQBt6zovEtJfOc6/site/?key=statement) [](193)

View file

@ -146,9 +146,8 @@ const ModuleOrdering: {[key: string]: ModuleOrderingItem[]} = {
{
name: "Strings",
items: [
"tries",
"suffix-array",
"string-search",
"suffix-array",
]
},
{