Simple Sum Problem

Time Limit
1s
Memory Limit
32768KB
Judge Program
Standard
Ratio(Solve/Submit)
24.85%(42/169)
Description:

You should already be familiar with the A +B problem and the following is an upgraded version. There is an array whose length is n. Captain Huang has Q queries. In each query, she may ask the sum of elements whose index is in the Interval [L,R].

Input:

The first line has two integer n and Q (1<n<1e51<Q<1e5) which represent the length of array and the number of queries respectively. Next line supplies n integer as an array. And the following Q lines represent queries. In each query, there are two integers L, R (1<=L<=R<=n).

Output:

For each query, output the sum of elementswhose index is in the Interval [L,R].

Sample Input:
5 3
1 2 3 4 5
1 3
1 5
3 4
Sample Output:
6
15
7

Submit