#C3420. Range Sum Queries

    ID: 46846 Type: Default 1000ms 256MiB

Range Sum Queries

Range Sum Queries

You are given an array of \(N\) integers and \(Q\) queries. Each query consists of two indices \(L\) and \(R\) (0-indexed). Your task is to compute the sum of the elements in the subarray from index \(L\) to \(R\) inclusive. The sum for any query can be computed efficiently using a prefix sum array. In particular, if we denote the prefix sum array by \(\text{prefix}\), then the answer for a query is given by:

\(S = prefix[R+1] - prefix[L]\)

Implement a solution that reads the input from standard input (stdin) and outputs the results to standard output (stdout).

inputFormat

The input is given as follows:

  • The first line contains an integer \(N\), the number of elements.
  • The second line contains \(N\) space-separated integers representing the array.
  • The third line contains an integer \(Q\), the number of queries.
  • Each of the next \(Q\) lines contains two space-separated integers \(L\) and \(R\) representing a query.

outputFormat

For each query, output a single line containing the sum of the elements in the specified range.

## sample
1
5
1
0 0
5