Introduction to Range Query Problems for Beginners [C++]

Revision en1, by Jellyman102, 2020-06-22 19:50:46

Author's Disclaimer: The following content is targeted towards those who are unfamiliar with range queries and how they work. If you are familiar with BITs, segment trees, and prefix sums, you will likely not learn anything new from reading this.

Author's Disclaimer #2: This is my first blog in a series of blogs I plan on writing that introduce various types of problems to beginner competitive programmers. That being said, I am by definition a beginner myself (regardless of my rating or competitive math experience, I have been doing this for less than a year). If you have any suggestions on how these could be improved, don't be afraid to speak up.

Basic Sum Queries (Prefix Sums)

Let's say we have some array $$$A$$$ = $$$A_{1}$$$, $$$A_{2}$$$, ..., $$$A_{n}$$$. Given two indices $$$i$$$ and $$$j$$$, we are tasked to find the following sum.

$$$\sum_{k=i}^{j} A_{k}$$$
Tags #bit, #segment tree, #range query, #c++, #beginner, prefix sum, #math

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en17 English Jellyman102 2020-06-23 01:30:06 332
en16 English Jellyman102 2020-06-23 00:36:16 0 (published)
en15 English Jellyman102 2020-06-23 00:32:28 154
en14 English Jellyman102 2020-06-23 00:31:18 123
en13 English Jellyman102 2020-06-23 00:29:17 5 Tiny change: 'your BITs 0-based!\n\' -> 'your BITs zero-based!\n\'
en12 English Jellyman102 2020-06-23 00:27:14 9 Tiny change: 'or reading thus far. Happy co' -> 'or reading. Happy co'
en11 English Jellyman102 2020-06-23 00:26:24 9 Tiny change: 'ng a blog about this sinc' -> 'ng a blog like this sinc'
en10 English Jellyman102 2020-06-23 00:25:42 134
en9 English Jellyman102 2020-06-23 00:23:26 153
en8 English Jellyman102 2020-06-23 00:18:53 2446
en7 English Jellyman102 2020-06-23 00:01:27 1668
en6 English Jellyman102 2020-06-22 23:37:50 20
en5 English Jellyman102 2020-06-22 23:36:53 288
en4 English Jellyman102 2020-06-22 23:23:05 68 Tiny change: 'exed tree comes in.' -> 'exed tree (also known as a Fenwick tree) comes in.'
en3 English Jellyman102 2020-06-22 23:04:30 978
en2 English Jellyman102 2020-06-22 20:18:35 1960 Tiny change: 'p_{j} - dp{i-1}$. ' -> 'p_{j} - dp_{i-1}$. '
en1 English Jellyman102 2020-06-22 19:50:46 925 Initial revision (saved to drafts)