54. Range Sum Queries
MediumPrefix Sum
Answer q queries. Each query gives l and r (1-based, inclusive); print the sum of a[l..r].
Input format
Line 1: n Line 2: n integers Line 3: q Next q lines: l r
Output format
One sum per line.
Example 1
Input
5 1 2 3 4 5 3 1 5 2 4 3 3
Output
15 9 3
Example 2
Input
3 -1 4 -2 2 1 2 2 3
Output
3 2
Constraints
1 ≤ n, q ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…