A range query library

The problem

Build a small C++ program that answers many questions about an array quickly: range sums, range additions, best windows and the number of subarrays with a given sum, and show that each is fast on a big input.

Requirements

Technologies

Step by step

  1. Read the array and the queries with fast input.
  2. Build the prefix-sum array and answer the range-sum queries.
  3. Apply the range additions with a difference array and rebuild the array.
  4. Add the window and subarray-count functions and test each against a slow brute force on small inputs.

Expected result

A program that answers 10⁵ queries on an array of 10⁵ numbers in well under a second, with tests that compare it to simple slow code.

How it is evaluated

Ways to improve it