#C7500. Range Sum Queries
Range Sum Queries
Range Sum Queries
You are given an array of integers and several queries. For each query, you are provided with two indices l and r. Your task is to compute the sum of the subarray from index l to r (inclusive).
The sum for a query can be represented by the following formula in LaTeX:
\( S = \sum_{i=l}^{r} a_i \)
The input is taken from standard input (stdin) and the result should be printed to standard output (stdout), with each answer printed on a new line.
Note: Ensure your solution can handle large integer values and edge cases such as empty input or single element queries.
inputFormat
The first line contains two integers N
and Q
where N
is the length of the array and Q
is the number of queries.
The second line contains N
space-separated integers representing the elements of the array.
Each of the next Q
lines contains two integers l
and r
indicating the indices (0-indexed) for the query.
outputFormat
For each query, output a line containing the sum of the elements within the specified range.
## sample5 1
1 2 3 4 5
0 2
6
</p>