Problem list
Log in
#r03328 · Online Judge > GoldOJ

Range Sum Queries

Silver III 2.0 s 256 MB

Given a sequence of $N$ integers ($1$-indexed), answer $Q$ queries: each query $(i, j)$ asks for the sum of $A_i + A_{i+1} + \dots + A_j$.

Input

First line $N$ and $Q$; second line $N$ integers ($-1000 \le A_i \le 1000$); then $Q$ lines each with $i$, $j$ ($1 \le i \le j \le N$).

Output

Print each query's sum on its own line.

Example 1

Input
6 3
5 4 3 2 -1 8 
1 6
5 5
2 5
Output
21
-1
8
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code