-
You have a list with the integers $A_0, A_1, \dots , A_{N-1}$.
Your task is to answer $Q$ queries of the form ”compute $A_L+A_{L+1}+\cdots +A_{R}$”, where $L$ and $R$ are different for query.
Indata
The first line of input contains two integers $N, Q$ ($1 \leq N \leq 3 \cdot 10^5$, $1 \leq Q \leq 10^5$).
The next line contains $N$ positive integers $A_0, A_1, \dots , A_{N-1}$ ($1 \leq A_i \leq 10^9$).
Afterwards, $Q$ lines follow, each containing two integers $L_{i},R_{i}$ ($0 \leq L_{i} \leq R_{i} \leq N-1$).
Utdata
Output $Q$ rows, with the $i$:th one containing the answer to the $i$:th question.
Group
Point value
Constraints
$1$
$50$
$N,Q \leq 1000$
$2$
$50$
No additional constraints.
Explanation of sample 1
In the first query, $L=0$ and $R=3$. Therefore, the answer is $A_0+A_1+A_2+A_3=1+4+3+1=9$.
Sample Input 1 Sample Output 1 5 4 1 4 3 1 2 0 3 0 1 2 3 1 2
9 5 4 7
Sample Input 2 Sample Output 2 3 1 1000000000 1000000000 1000000000 0 2
3000000000
-
To solve the problems, you can either start a virtual contest or register for regular practice. A virtual contest simulates a participation in the original contest with a duration of 1 day, while regular practice lets you submit solutions without any constraints.
You must log in to register. - 1 Range Sum 1
- 2 Range Sum 2
- 3 Range Sum 3
- 4 Range Sum 4
- 5 Range Sum 5
- 6 Range Sum 6