#K74307. Prefix Sum Queries for Rider Energies

    ID: 34168 Type: Default 1000ms 256MiB

Prefix Sum Queries for Rider Energies

Prefix Sum Queries for Rider Energies

You are given n riders, each with an associated energy value. Your task is to answer q queries. Each query provides two indices i and j (1-indexed) and asks for the sum of the riders' energy values from position i to j (inclusive).

To solve this problem efficiently, you are advised to use the prefix sum technique. The prefix sum array P can be computed using the following formula in \( \LaTeX \):

P[i]=P[i1]+a[i]P[i] = P[i-1] + a[i]

where \( a[i] \) is the energy value of the \( i^{th} \) rider. Note that the provided indices in the queries are 1-indexed.

inputFormat

The first line contains an integer n representing the number of riders.

The second line contains n space-separated integers where the \( i^{th} \) integer represents the energy value of the \( i^{th} \) rider.

The third line contains an integer q representing the number of queries.

Each of the following q lines contains two integers i and j (1-indexed) representing a query that asks for the sum of energy values from index i to j inclusive.

outputFormat

For each query, output a single integer on a new line which is the sum of the energy values from index i to j inclusive.

## sample
5
7 3 2 5 1
3
1 3
2 4
1 5
12

10 18

</p>