Problem 05A. Range Sum Queries ≡

Author:Pavel Mesenev   Time limit:2 sec
Input file:Standard input   Memory limit:256 Mb
Output file:Standard output  

Statement

You are given an array a0, a1, …, an − 1 of integers and q queries. Each query is a pair (l, r) with 0 ≤ l ≤ r ≤ n − 1; answer with al + al + 1 + …  + ar.

Input format

The first line contains two integers n and q. The second line contains n space-separated integers a0… an − 1. Each of the next q lines contains two integers l and r.

Output format

Print q lines: the answer to each query, in order.

Constraints

1 ≤ n, q ≤ 2 ⋅ 105

 − 109 ≤ ai ≤ 109

Every answer fits into a signed 64-bit integer.

Sample tests

No. Standard input Standard output
1
6 3
1 2 3 4 5 6
0 2
3 5
0 5
6
15
21
2
5 2
-3 -1 4 -2 5
1 3
0 0
1
-3

0.045s 0.018s 16