+ 1DSRQ, modify intro

This commit is contained in:
Benjamin Qi 2020-06-21 23:32:32 -04:00
parent 6968f74722
commit 94f295778e
8 changed files with 121 additions and 103 deletions

View file

@ -7,7 +7,7 @@ description: Learn about the basic data types needed for competitive programming
There are several main **data types** that are used in contests: 64-bit integers, floating point numbers, booleans, characters, and strings. Assuming that you are familiar with the language you are using, this should be mostly review.
Use 64-bit integers (long long in C++) instead of 32-bit integers (int). 64-bit integers are less likely to have overflow issues, since they can store any number between $-9\,223\,372\,036\,854\,775\,808$ and $9\,223\,372\,036\,854\,775\,807$ which is roughly equal to $\pm$ $9 \times 10^{18}$. Contest problems are usually set such that the 64-bit integer is sufficient.
It's a good idea to use 64-bit integers (`long long` in C++) instead of 32-bit integers (`int`). 64-bit integers are less likely to have overflow issues, since they can store any number between $-9\,223\,372\,036\,854\,775\,808$ and $9\,223\,372\,036\,854\,775\,807$ which is roughly equal to $\pm 9 \times 10^{18}$. Contest problems are usually set such that the 64-bit integer is sufficient. Of course, you shouldn't do this when time and/or memory limits are tight, which may be the case in higher divisions of USACO.
**Floating point numbers** are used to store decimal values. It is important to know that floating point numbers are not exact, because the binary architecture of computers can only store decimals to a certain precision. Hence, we should always expect that floating point numbers are slightly off. Contest problems will accommodate this by either asking for the greatest integer less than $10^k$ times the value, or will mark as correct any output that is within a certain $\epsilon$ of the judge's answer.

View file

@ -12,7 +12,7 @@ prerequisites:
- Intro - Data Types
-
- Intro - Input & Output
description: Solutions for an "USACO Bronze - Fence Painting" in multiple languages.
description: Solutions for "USACO Bronze - Fence Painting" in multiple languages.
---
[Technical Specifications for USACO Contests](http://www.usaco.org/index.php?page=instructions)

View file

@ -1,58 +0,0 @@
---
id: getting-started
title: Getting Started
author: Nathan Wang, Benjamin Qi, Darren Yao
description: Introduces the guide and how to choose a language.
---
## Module Organization
All material will be grouped into **modules** such as the one you're reading right now.
### Guidelines
- Should be a "one stop shop," meaning that this is the only site you have to use to be exposed to most (if not all) of the topics required for Bronze - Gold.
- The idea is that people will no longer have to go resource hunting as well do all of that for them.
- "Dont Reinvent the Wheel"
- We'll link to online resources that already exist whenever possible.
- Not *just* a collection of links
- There exist plenty of resources out there, but we do not expect users to click through all of them to find the information they want.
- This means in addition to the link itself we need to provide information about what the link is about as well as the quality of the link.
- We dont want to say something like "learn DP, here are 50 links that can teach you that." Instead, we want to say "learn DP by first reading this one article, then reading this other article. For reference, here are some other links you can explore as you wish."
### Lesson
- Consists of text, videos, and simple problems.
- Goal is to introduce user to the concept.
- Everything should be completed in order.
- Any problems here should be pure implementation.
- Languages
- Include C++ and Java for all divisions. (C++ takes priority)
- Possibly Python for Bronze.
### Practice
- Link the relevant past USACO problems (and other recommended problems).
- Problems should be sorted in order of how they are recommended be completed.
- Add comments regarding difficulty and / or solution sketches.
- Possibly include additional problems.
## Choosing a Language
The most popular languages that USACO supports are C++11, Java, and Python 3. In general, we recommend the following:
- If you already know one of these languages, just use it.
- If you know multiple languages, we recommend you pick C++ over Java, and Java over Python.
- For Bronze, any language will do.
- For Silver, Gold, and Platinum, Python is not recommended.
Keep in mind that it's easy to switch languages down the road. Don't get caught up on which language to choose. Just pick the one you feel most comfortable with!
### Language References
All of these are provided at the IOI aside from the additional C++ reference.
- [C++](https://en.cppreference.com/w/)
- [Additional C++ Reference](http://www.cplusplus.com/)
- [Java](https://docs.oracle.com/javase/8/docs/api/overview-summary.html)
- [Python3](https://docs.python.org/3/reference/)

View file

@ -1,25 +1,60 @@
---
id: intro
title: Introduction to Programming Competitions
title: Introduction
author: Nathan Wang, Benjamin Qi, Darren Yao
description: Explain what programming competitions are.
description: Welcome to the guide! We'll introduce what programming competitions are and how this guide is organized.
---
A **programming competition** generally lasts for several hours and consists of a set of problems. These problems are not open problems; they have already been solved by the problem writer(s) and tester(s) and (hopefully) are designed to be solved in the short timeframe of a contest. In general, each problem in competitive programming is solved by a two-step process:
A [programming competition](https://en.wikipedia.org/wiki/Competitive_programming) generally lasts for several hours and consists of a set of problems. These problems are not open problems; they have already been solved by the problem writer(s) and tester(s) and (hopefully) are designed to be solved in the short timeframe of a contest. In general, each problem in competitive programming is solved by a two-step process:
1. coming up with the algorithm, which involves problem solving skills and intuition
2. implementing the algorithm, which requires programming skills to translate the algorithm into working code.
For each problem, when you complete your code you submit it to a grader, which checks the answers calculated by the your program against a set of predetermined test cases. For each problem, you are given a time limit (usually 2 seconds) and a memory limit (usually 256 megabytes) that your program must satisfy.
For each problem, when you complete your code you submit it to a grader, which checks the answers calculated by the your program against a set of predetermined test cases. For each problem, you are given a time limit (usually 2 seconds) and a memory limit (usually 256 [megabytes](https://en.wikipedia.org/wiki/Megabyte)) that your program must satisfy.
For those of you with experience in software development, note that competitive programming is quite different, as the goal is to write programs that compute the correct answer, run quickly, and can be implemented quickly. Note that nowhere was maintainability of code mentioned. So you don't need to bother documenting your code because it only needs to be readable to you during the contest.
### Videos
### More Information
- [William Lin - What is Competitive Programming?](https://www.youtube.com/watch?time_continue=1&v=ueNT-w7Oluw)
- [Kamil Debowski - Interview with a Competitive Programmer](https://www.youtube.com/watch?v=F4rykKLcduI)
- [Task](https://open.kattis.com/contests/mcpc19open/problems/basketballoneonone) that was mentioned in video.
- Videos
- [William Lin - What is Competitive Programming?](https://www.youtube.com/watch?time_continue=1&v=ueNT-w7Oluw)
- [Kamil Debowski - Interview with a Competitive Programmer](https://www.youtube.com/watch?v=F4rykKLcduI)
- [Task](https://open.kattis.com/contests/mcpc19open/problems/basketballoneonone) that was mentioned in video.
- Reading
- [PAPC Ch 1](http://www.csc.kth.se/~jsannemo/slask/main.pdf)
## Contest Format
The [USA Computing Olympiad](http://www.usaco.org/index.php?page=contests) is a national programming competition that occurs four times a year, with December, January, February, and US Open (March) contests. The regular contests are four hours long, and the US Open is five hours long. Each contest contains three problems. Solutions are evaluated and scored against a set of predetermined test cases that are not visible to the student. Scoring is out of 1000 points, with each problem being weighted equally (\~333 points). There are four divisions of contests: Bronze, Silver, Gold, and Platinum. After each contest, students who meet the contest-dependent cutoff for promotion will compete in the next division for future contests.
The [USA Computing Olympiad](http://www.usaco.org/index.php?page=contests) is a national programming competition that occurs four times a year, with December, January, February, and US Open (March) contests. The regular contests are four hours long, and the US Open is five hours long. Each contest contains three problems. Solutions are evaluated and scored against a set of predetermined test cases that are not visible to the student. Scoring is out of 1000 points, with each problem being weighted equally (\~333 points). There are four divisions of contests: Bronze, Silver, Gold, and Platinum. After each contest, students who meet the contest-dependent cutoff for promotion will compete in the next division for future contests.
## Module Organization
All material in this guide will be grouped into **modules** such as the one you're reading right now.
### Guidelines
- Should be a "one stop shop," meaning that this is the only site you have to use to be exposed to most (if not all) of the topics required for Bronze - Gold.
- The idea is that people will no longer have to go resource hunting as well do all of that for them.
- "Dont Reinvent the Wheel"
- We'll link to online resources that already exist whenever possible.
- Not *just* a collection of links
- There exist plenty of resources out there, but we do not expect users to click through all of them to find the information they want.
- This means in addition to the link itself we need to provide information about what the link is about as well as the quality of the link.
- We dont want to say something like "learn DP, here are 50 links that can teach you that." Instead, we want to say "learn DP by first reading this one article, then reading this other article. For reference, here are some other links you can explore as you wish."
### Lesson
- Consists of text, videos, and simple problems.
- Goal is to introduce user to the concept.
- Everything should be completed in order.
- Any problems here should be pure implementation.
- Languages
- Include C++ and Java for all divisions. (C++ takes priority)
- Possibly Python for Bronze.
### Practice
- Link the relevant past USACO problems (and other recommended problems).
- Problems should be sorted in order of how they are recommended be completed.
- Add comments regarding difficulty and / or solution sketches.
- Possibly include additional problems.

View file

@ -2,12 +2,32 @@
id: prereqs
title: Prerequisites
author: Nathan Wang, Benjamin Qi
description: Here's what you should know before continuing onwards.
description: What languages you can use and what you should know before continuing.
---
## Choosing a Language
The most popular languages that USACO supports are [C++11](https://en.wikipedia.org/wiki/C%2B%2B), [Java](https://en.wikipedia.org/wiki/Java_(programming_language)), and [Python 3](https://en.wikipedia.org/wiki/Python_(programming_language)). In general, we recommend the following:
- If you already know one of these languages, just use it.
- If you know multiple languages, we recommend you pick C++ over Java, and Java over Python.
- For Bronze, any language will do.
- For Silver, Gold, and Platinum, Python is not recommended.
Keep in mind that it's easy to switch languages down the road. Don't get caught up on which language to choose. Just pick the one you feel most comfortable with!
### Language References
All of these are provided at the IOI aside from the additional C++ reference.
- [C++](https://en.cppreference.com/w/)
- [Additional C++ Reference](http://www.cplusplus.com/)
- [Java](https://docs.oracle.com/javase/8/docs/api/overview-summary.html)
- [Python3](https://docs.python.org/3/reference/)
## Expected Knowledge
This guide assumes that you know the basics of how to code, including the following topics:
The remainder of this guide assumes that you know the basics of how to code in one of the languages listed above, including the following topics:
- Variables
- Data types
@ -21,22 +41,26 @@ This guide assumes that you know the basics of how to code, including the follow
- Arrays
- Multidimensional Arrays
In particular, contestants using Java should be familiar with roughly the first half of AP Computer Science A. If you do not meet these prerequisites, see the links below to get started.
In particular, contestants using Java should be familiar with roughly the first half of AP Computer Science A.
Familiarity with [competition math](https://github.com/bqi343/USACO/blob/master/Resources/Competition%20Math.md) (ex. AIME qualification) is helpful but not required.
- If you do not meet these prerequisites, see the links below to get started.
- Familiarity with [competition math](https://github.com/bqi343/USACO/blob/master/Resources/Competition%20Math.md) (ex. AIME qualification) is helpful but not required.
## Resources for Learning How to Code
[Sololearn](https://www.sololearn.com/) has courses on C++, Java, and Python. You don't have to complete the full course.
- For C++, we recommend you finish Sololearn up to (but not including) "More on Classes."
### C++
- We recommend you finish Sololearn up to (but not including) "More on Classes."
- Also see [Ch 2 of PAPS](http://www.csc.kth.se/~jsannemo/slask/main.pdf)
[[info | Pro Tip]]
| You do not need to learn pointers (for now). Knowledge of structs and classes is useful but not required.
## Resources for Getting Started
Note: We don't agree with all views expressed in the links below. Feel free to let us know what works (or doesn't) for you.
Note: We don't agree with all views expressed in the links below. Let us know what works (or doesn't) for you.
- [CodeSignal](https://codesignal.com/)
- can practice basics with "Arcade," "Interview Practice"

View file

@ -2,13 +2,10 @@
id: resources
title: Additional Resources
author: Benjamin Qi
description: A bunch of helpful links.
---
<module-excerpt>
Helpful Links! Some (such as **CPH** and **Intro to USACO**) will be mentioned again in later modules.
</module-excerpt>
Some (such as **CPH** and **Intro to USACO**) will be mentioned again in later modules.
## Lists
@ -20,7 +17,7 @@ Helpful Links! Some (such as **CPH** and **Intro to USACO**) will be mentioned a
* [Competitive Programmer's Handbook (CPH)](https://cses.fi/book/book.pdf)
* The [CSES problemset](https://cses.fi/problemset/) (now at 200 problems) is quite good!
* [Guide to Competitive Programming](https://www.amazon.com/Guide-Competitive-Programming-Algorithms-Undergraduate/dp/3319725467) is a paid book based off CPH
* Can currently download PDF [for free](https://link.springer.com/book/10.1007/978-3-319-72547-5)!
* Can currently download PDF for [free](https://link.springer.com/book/10.1007/978-3-319-72547-5)!
* Intro to USACO (Darren Yao)
* Bronze, Silver
* [Java](http://darrenyao.com/usacobook/java.pdf)
@ -29,25 +26,38 @@ Helpful Links! Some (such as **CPH** and **Intro to USACO**) will be mentioned a
* [Competitive Programming Book 1](http://www.comp.nus.edu.sg/~stevenha/myteaching/competitive_programming/cp1.pdf) is freely available but old
* [Competitive Programming 4](https://cpbook.net/) is the latest edition of the book (with significant additions) but costs money.
* Release date is July 19th, 2020.
* [Principles of Algorithmic Problem Solving (PAPS)](http://www.csc.kth.se/~jsannemo/slask/main.pdf)
* [Samuel Hsiang - CS Guide](https://github.com/alwayswimmin/cs_guide)
* [TJSCT](https://activities.tjhsst.edu/sct/)
* [TJIOI](https://github.com/tjsct/tjioi-study-guide)
* [Principles of Algorithmic Problem Solving](http://www.csc.kth.se/~jsannemo/slask/main.pdf)
* [Cracking the Coding Interview](http://www.crackingthecodinginterview.com/) is a good book specifically for programming interviews (it is not needed for USACO).
* [Cracking the Coding Interview](http://www.crackingthecodinginterview.com/)
* good book specifically for programming interviews
## Courses
* [Competitive Programming Course (SuprDewd)](https://github.com/SuprDewd/T-414-AFLV)
* [Cousera Algorithms Pt 1 (and Pt 2)](https://www.coursera.org/learn/algorithms-part1)
* [Carnegie-Mellon ICPC](https://contest.cs.cmu.edu/295/f17/)
* [VPlanet](https://vplanetcoding.com/)
* [Carnegie-Mellon ICPC Course](https://contest.cs.cmu.edu/295/f17/)
* topic-specific contests in CF group
## Algorithm Collections
* [CSAcademy](https://csacademy.com/lessons/)
* [cp-algorithms](https://cp-algorithms.com/)
* [KTH ICPC Team Reference (KACTL)](https://github.com/kth-competitive-programming/kactl)
* [bqi343 Github](https://github.com/bqi343/USACO)
* [Topcoder Tutorials](http://www.topcoder.com/community/data-science/data-science-tutorials/)
* [Topcoder Data Science Tutorials](http://www.topcoder.com/community/data-science/data-science-tutorials/)
* [List of CF Tutorials](http://codeforces.com/blog/entry/57282)
* [ekzlib](http://ekzlib.herokuapp.com)
## By USACO Finalists
- [VPlanet](https://www.vplanetcoding.com/courses)
- Riya Arora
- courses for various levels
- [ekzlib](http://ekzlib.herokuapp.com)
- Eric Zhang
- (advanced) implementations
- [bqi343 USACO Github](https://github.com/bqi343/USACO)
- Benjamin Qi
- implementations
- ICPC book
- past USACO solutions

View file

@ -7,34 +7,42 @@ prerequisites:
- Gold - Binary Indexed Trees
---
Given a static array $A[1],A[2],\ldots,A[N]$, you want to answer queries in the form $A[l]\ominus A[l+1]\ominus \cdots \ominus A[r]$ in $O(1)$ time each with $O(N\log N)$ time preprocessing, where $\ominus$ denotes any associative operation. In the case when $\ominus$ denotes `min`, preprocessing can be done in $O(N)$ time.
Given a static array $A[1],A[2],\ldots,A[N]$, you want to answer queries in the form $A[l]\ominus A[l+1]\ominus \cdots \ominus A[r]$ in $O(1)$ time each with $O(N\log N)$ time preprocessing, where $\ominus$ denotes any associative operation.
## [Range Minimum Query](https://en.wikipedia.org/wiki/Range_minimum_query)
Consider the case when $\ominus$ denotes `min`.
- [CSES Range Minimum Queries I](https://cses.fi/problemset/task/1647)
### Tutorial
- [Range Minimum Query](https://en.wikipedia.org/wiki/Range_minimum_query)
- Use for $O(1)$ LCA
- CPH 9.1
- [cp-algorithms RMQ](https://cp-algorithms.com/sequences/rmq.html)
- [$O(1)$ Query RMQ with $O(N)$ build](https://codeforces.com/blog/entry/78931)
- CPH 9.1
- [cp-algorithms RMQ](https://cp-algorithms.com/sequences/rmq.html)
In fact, preprocessing can be done in $O(N)$ time.
- [$O(1)$ Query RMQ with $O(N)$ build](https://codeforces.com/blog/entry/78931)
### Divide & Conquer
**Divide & conquer** can refer to many different techniques. In this case, we use it to answer $Q$ queries offline in $O((N+Q)\log N)$ time.
Suppose that all queries satisfiy $L\le l\le r\le R$ (initially, $L=1$ and $R=N$). Letting $M=\left\lfloor \frac{L+R}{2}\right\rfloor$, we can compute
$$lef[l]=A[l]\ominus A[l+1]\ominus \cdots \ominus A[M]$$
$$
lef[l]=A[l]\ominus A[l+1]\ominus \cdots \ominus A[M]
$$
for all $L\le l\le M$ and
$$rig[r]=A[M+1]\ominus A[M+2] \ominus \cdots\ominus A[r]$$
$$
rig[r]=A[M+1]\ominus A[M+2] \ominus \cdots\ominus A[r]
$$
for each $M< r\le R$. Then the answer for all queries satisfying $l\le M< r$ is simply $lef[l]\ominus rig[r]$ due to the associativity condition. After that, we recurse on all query intervals completely contained within $[L,M]$ and $[M+1,R]$ independently.
Actually, this can be adjusted to answer queries online in $O(1)$ time each. See my implementation [here](https://github.com/bqi343/USACO/blob/master/Implementations/content/data-structures/Static%20Range%20Queries%20(9.1)/RangeQuery.h).
See my implementation [here](https://github.com/bqi343/USACO/blob/master/Implementations/content/data-structures/Static%20Range%20Queries%20(9.1)/RangeQuery.h).
#### Problems
- [DMOJ Continued Fractions](https://dmoj.ca/problem/dmopc19c7p4)
- [USACO Plat - NonDec](http://www.usaco.org/index.php?page=viewproblem2&cpid=997)
- [JOI Secret](https://oj.uz/problem/view/JOI14_secret)
- [Codechef - Product on Segment](https://www.codechef.com/problems/SEGPROD)
- [DMOJ - Continued Fractions](https://dmoj.ca/problem/dmopc19c7p4)
- [USACO Plat - Non-Decreasing Subsequences](http://www.usaco.org/index.php?page=viewproblem2&cpid=997)
- [JOI - Secret](https://oj.uz/problem/view/JOI14_secret)

View file

@ -1,7 +1,6 @@
const ModuleOrdering = {
"intro": [
"intro",
"getting-started",
"prereqs",
"running-cpp",
"data-types",
@ -24,8 +23,8 @@ const ModuleOrdering = {
},
],
"bronze": [
"rect-geo",
"time-comp",
"rect-geo",
{
name: "Data Structures",
items: [