~/algor $ cat problems/massiv-oraliq-yigindilar
Range sums
Medium
1000 ms
128 MB
66%
An array a of n integers and q queries are given. Each query gives two numbers l and r: find the sum a_l + a_{l+1} + … + a_r. There are many queries, so computing each one separately will not fit in the time limit.
Input
The first line contains n and q. The second line contains n integers — a_1, a_2, …, a_n. Each of the next q lines contains two numbers l and r.
Output
q lines: the sum for each query.
Note
1 ≤ n, q ≤ 200 000; −10⁹ ≤ a_i ≤ 10⁹; 1 ≤ l ≤ r ≤ n. The sum may not fit in a 32-bit integer.
Examples
Input #1
5 3 1 2 3 4 5 1 3 2 5 4 4
Output #1
6 14 4
Input #2
4 2 -5 10 -3 7 1 4 2 3
Output #2
9 7