This repository has been archived on 2022-06-22. You can view files and clone it, but cannot push or open issues or pull requests.
usaco-guide/content/2_Silver/6_Silver_Psum.md

44 lines
1 KiB
Markdown
Raw Normal View History

2020-06-04 01:42:57 +00:00
---
slug: /silver/prefix-sums
2020-06-04 05:39:49 +00:00
title: "Prefix Sums"
2020-06-04 02:16:50 +00:00
author: Eric Wei (incomplete)
2020-06-04 05:39:49 +00:00
order: 6
2020-06-04 01:42:57 +00:00
---
2020-06-04 05:39:49 +00:00
<div class="syllabus-only">
Description: Todo
</div>
2020-06-03 20:16:33 +00:00
2020-06-04 05:39:49 +00:00
<!-- END DESCRIPTION -->
2020-06-04 02:16:50 +00:00
## The Task
Given an array of size $N$, answer $Q$ queries of the following form: Find the sum of all elements between indices $i$ and $j$.
- [CSES Range Sum Queries I](https://cses.fi/problemset/task/1646)
## Tutorials
(This technique is also known as *cumulative sum* or *partial sums*.)
2020-06-03 20:16:33 +00:00
See Ch 11 of https://www.overleaf.com/project/5e73f65cde1d010001224d8a
2020-06-04 02:16:50 +00:00
- CPH 9.1
## Extensions
### 2D Prefix Sums
Given a 2-Dimension array of size $NxM$, answer $Q$ queries of the following form: Find the sum of all elements within the rectangle of indices $(x1,y1)$ to $(x2,y2)$.
- [CSES Forest Queries](https://cses.fi/problemset/task/1652)
### Difference Array
Consider the array formed by $a_i-a_{i-1}$.
- [USACO Painting the Barn](http://www.usaco.org/index.php?page=viewproblem2&cpid=919) (i should find an easier one because this is hard)
### Prefix Minimum, Etc.
Using