#P8218. 【深进1.例1】求区间和

【深进1.例1】求区间和

Problem Description

Given a sequence a1,a2,,ana_1, a_2, \cdots, a_n consisting of nn positive integers and mm intervals [li,ri][l_i, r_i], find the sum of elements in each of the mm intervals.

Input Format

The first line contains a positive integer nn, representing the length of the sequence.

The second line contains nn positive integers a1,a2,,ana_1, a_2, \cdots, a_n.

The third line contains a positive integer mm, representing the number of intervals.

The next mm lines each contain two positive integers li,ril_i, r_i, satisfying 1lirin1 \le l_i \le r_i \le n.

Output Format

Output mm lines. The ii-th line contains a positive integer, representing the answer to the ii-th query.

4
4 3 2 1
2
1 4
2 3
10
5

Hint

Sample Explanation

The sum of the 11st to the 44th numbers is 1010. The sum of the 22nd to the 33rd numbers is 55.

Constraints

For 50%50\% of the testdata: n,m1000n, m \le 1000.

For 100%100\% of the testdata: 1n,m1051 \le n, m \le 10^5, 1ai1041 \le a_i \le 10^4.

Translated by ChatGPT 5