#K96177. Range Sum Queries on Scores

    ID: 39029 Type: Default 1000ms 256MiB

Range Sum Queries on Scores

Range Sum Queries on Scores

You are given an array of scores for N participants and Q queries. Each query asks for the sum of scores in a specific range. The range is specified by two indices L and R. Your task is to answer each query by computing the sum:

\( S = \sum_{i=L}^{R} scores[i] \)

To solve the problem efficiently, you can precompute a prefix sum array. Let \( P[i] \) be the sum of the first \( i \) scores. Then the sum for the range is:

\( S = P[R] - P[L-1] \)

Note that the indices are 1-indexed. Ensure that you process input from stdin and output your answers to stdout as specified.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains two integers, N and Q, separated by a space, where N is the number of participants and Q is the number of queries.
  • The second line contains N integers representing the scores of the participants.
  • The next Q lines each contains two integers L and R representing a query for the sum of scores from index L to R (1-indexed).

outputFormat

For each query, output a single integer – the sum of scores in the range [L, R]. Each result should be printed on a new line to stdout.

## sample
5 3
1 2 3 4 5
1 3
2 4
1 5
6

9 15

</p>