This commit is contained in:
Benjamin Qi 2020-06-09 14:34:04 -04:00
parent 8e99459134
commit 76e9f36b00
6 changed files with 35 additions and 30 deletions

View file

@ -31,7 +31,7 @@ order: 1
## Module Organization
Written with [markdown](https://www.markdownguide.org/cheat-sheet/).
Written with [Markdown](https://www.markdownguide.org/cheat-sheet/). Can use [StackEdit](https://stackedit.io/) to check latex.
### Lesson

View file

@ -18,6 +18,7 @@ Using C++ both online and locally (currently for Mac only).
* make sure your code is not public
* sometimes randomly erases your code when you first create it (so get in the habit of copying your code before creating it!)
* [OnlineGDB](https://www.onlinegdb.com/)
* compiler and debugger tool
Of course, you can't use File I/O on these websites (or do a lot of other stuff ...).
@ -27,7 +28,9 @@ Of course, you can't use File I/O on these websites (or do a lot of other stuff
## Installation
Open **Terminal** and run
Open **Terminal**. First, familiarize yourself with some basic commands given [here](https://blog.teamtreehouse.com/introduction-to-the-mac-os-x-command-line).
Run
```sh
brew install gcc
@ -110,11 +113,13 @@ If you want to read input from `inp.txt` and write to `out.txt`, then use the fo
./name < inp.txt > out.txt
```
See "Introductory Problems" for how to do file input and output within the program.
See "Intro - Introductory Problems" for how to do file input and output within the program.
### Adding Shortcuts
Retyping this command gets tedious once we start adding many [command line options](https://developers.redhat.com/blog/2018/03/21/compiler-and-linker-flags-gcc/). See "General - Debugging" for more information about compilation options.
[Aliases in Terminal](https://jonsuh.com/blog/bash-command-line-shortcuts/)
Retyping the commands for compiling and running gets tedious once we start adding many [command line options](https://developers.redhat.com/blog/2018/03/21/compiler-and-linker-flags-gcc/). See "General - Debugging" for more information about compilation options.
Open your bash profile with a text editor such as gedit (or sublime text).
@ -145,6 +150,7 @@ Note that all occurrences of `$1` are replaced with `name`.
* [Geany](https://www.geany.org/)
* used at IOI
* [Visual Studio Code](https://code.visualstudio.com/)
* haven't used personally
* [XCode](https://developer.apple.com/xcode/)
* Mac only
* [Codeblocks](http://www.codeblocks.org/)
@ -160,11 +166,4 @@ I mostly just use sublime text.
* [Sublime Snippets](https://www.granneman.com/webdev/editors/sublime-text/top-features-of-sublime-text/quickly-insert-text-and-code-with-sublime-text-snippets)
* [Symlink](https://www.sublimetext.com/docs/3/osx_command_line.html)
* Using `/usr/local/bin/subl` instead of `~/bin/subl` worked for me on OS X Mojave.
* [Atom](https://atom.io/)
## Other Useful Links
* [Intro to Command Line](http://blog.teamtreehouse.com/introduction-to-the-mac-os-x-command-line)
* [Command Line Shortcuts](https://jonsuh.com/blog/bash-command-line-shortcuts/)
* [Run Python Script](https://stackoverflow.com/questions/7855996/cant-run-python-py-files-from-terminal-on-mac)
* [Competitive C++ Style Guide](https://codeforces.com/blog/entry/64218)
* [Atom](https://atom.io/)

View file

@ -5,14 +5,15 @@ author: Benjamin Qi, Aaron Chew
order: 6
---
- Compilation Options
- CppIO Template
- Stress Testing
- Using a Debugger
Detecting issues within your program and figuring out how to avoid them in the first place.
<!-- END DESCRIPTION -->
(what is debugging?)
## Style Guide
[Swift](https://codeforces.com/blog/entry/64218)
## Compilation
As mentioned in "Running C++," I use the following to compile and run.
@ -21,8 +22,6 @@ co() { g++ -std=c++11 -O2 -o $1 $1.cpp -Wall -Wextra -Wshadow -DLOCAL -Wl,-stack
run() { co $1 && ./$1 & fg; }
```
## Compilation
### Warnings
See [here](https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html).

View file

@ -5,9 +5,15 @@ author: ?
order: 6
---
## [Pair](http://www.cplusplus.com/reference/utility/pair/pair/)
A **pair** is a structure that holds two values, not necessarily of the same type.
A structure that holds two values, not necessarily of the same type (not built into java!).
(tuple?)
<!-- END DESCRIPTION -->
(is this present in Java?)
## [C++](http://www.cplusplus.com/reference/utility/pair/pair/)
- `make_pair(a, b)`: Returns a pair with values a, b.
- `pair.first`: The first value of the pair.

View file

@ -2,7 +2,7 @@
slug: /bronze/complete-search
title: "Complete Search"
author: Unknown
order: 7
order: 8
---
See 6 of https://www.overleaf.com/project/5e73f65cde1d010001224d8a

View file

@ -47,7 +47,7 @@ Given a 2-dimensional array of size $NxM$, answer $Q$ queries of the following f
### Prefix Minimum, XOR, etc.
Similar to prefix sums, you can also take prefix minimum or maximum; but *you cannot* answer min queries over an arbitrary range with prefix minimum. (This is because minimum doesn't have an inverse operation, the way subtraction is to addition.)
On the other hand, XOR is its own inverse operation...
On the other hand, XOR is its own inverse operation, meaning that the XOR of any number with itself is zero.
- [USACO My Cow Ate My Homework](http://usaco.org/index.php?page=viewproblem2&cpid=762)
- [CSES Range XOR Queries](https://cses.fi/problemset/task/1650)
@ -56,15 +56,16 @@ On the other hand, XOR is its own inverse operation...
Instead of storing just the values themselves, you can also take a prefix sum over $i\cdot a_i$, or $10^i \cdot a_i$, for instance. Some math is usually helpful for these problems; don't be afraid to get dirty with algebra!
For instance, let's see how to quickly answer the following type of query: Find $1\cdot a_l+2\cdot a_{l+1}+3\cdot a_{l+2}+\cdots+(r-l+1)\cdot a_{r}$.
For instance, let's see how to quickly answer the following type of query: Find
$$1\cdot a_l+2\cdot a_{l+1}+3\cdot a_{l+2}+\cdots+(r-l+1)\cdot a_{r}.$$
First, define the following:
$ps[i] = a_1+a_2+a_3+a_4+\cdots+a_i$
$ips[i] = 1\cdot a_1+2\cdot a_2+\cdots+i\cdot a_i$
$$ps[i] = a_1+a_2+a_3+a_4+\cdots+a_i$$
$$ips[i] = 1\cdot a_1+2\cdot a_2+\cdots+i\cdot a_i$$
Then, we have:
$l\cdot a_l + (l+1) \cdot a_{l+1} + \cdots + r \cdot a_r = ips[r]-ips[l-1]$
$(l-1) \cdot a_l + (l-1) \cdot a_{l+1} + \cdot + (l-1) \cdot a_r = (l-1)(ps[r]-ps[l-1])$
$$l\cdot a_l + (l+1) \cdot a_{l+1} + \cdots + r \cdot a_r = ips[r]-ips[l-1]$$
$$(l-1) \cdot a_l + (l-1) \cdot a_{l+1} + \cdot + (l-1) \cdot a_r = (l-1)(ps[r]-ps[l-1])$$
And so,
$1\cdot a_l + 2 \cdot a_{l+1} + \cdots + (r-l+1) \cdot a_r = ips[r]-ips[l-1]-(l-1)(ps[r]-ps[l-1])$
$$1\cdot a_l + 2 \cdot a_{l+1} + \cdots + (r-l+1) \cdot a_r = ips[r]-ips[l-1]-(l-1)(ps[r]-ps[l-1])$$
Which is what we were looking for!
- [AtCoder Multiple of 2019](https://atcoder.jp/contests/abc164/tasks/abc164_d) (You may want to solve the below problem "Subsequences Summing to Seven" before doing this one.)