Skip to content
Back to libraryPart 2 · Core techniques

2.1Prefix sums

Before you start

It helps to have read 1.3 Arrays and strings and 1.2 Complexity and limits. Overall level: Core.

Practice: Prefix sums

0 of 4 solved

About these problems

Apply, Connect, Reason and Stretch describe difficulty within this topic, not an official contest rating. Open any problem in any order; reading the chapter first is optional.

  1. 1Range totalsAnswer q range-sum queries on an unchanged array. Each query gives inclusive, 1-based positions l and r.ApplyNot started
  2. 2Best fixed blockAmong all consecutive blocks of exactly k elements, print the largest sum. Values may be negative.ConnectNot started
  3. 3Range paint countsAn initially zero array has n positions. Each of q instructions adds integer v to every position in inclusive range l..r. After all instructions, print the final array.ReasonNot started
  4. 4Rectangle sensorsA grid contains 0 or 1 in each cell. Answer queries counting 1s in an inclusive rectangle with top-left(r1, c1) and bottom-right(r2, c2).StretchNot started

Read the lesson