PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000275. Tổng các tổng đoạn (Sums of Segments)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng các tổng đoạn (Sums of Segments)
Sums of Segments
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer array , define . Form by listing, for each start , the values in that order. Its length is . For example, yields . For each query , compute . Both arrays use 1-based indexing.
Input
Line 1 contains . Line 2 contains integers . Line 3 contains . Each of the next lines contains .
Output
Print one answer per line, in query order.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; ; for every query.
- Subtask 3 (50 points): ; ; ; .
Example 1
Input
4
1 2 5 10
15
1 1
1 2
1 3
1 4
1 5
1 10
5 10
6 10
2 8
3 4
3 10
3 8
5 6
5 5
1 8
Output
1
4
12
30
32
86
56
54
60
26
82
57
9
2
61
Explanation
The array b is (1,3,8,18,2,7,17,5,15,10). Query (2,8) sums 3+8+18+2+7+17+5=60; (5,6) sums 2+7=9. The other queries are evaluated in the same way.
Example 2
Input
3
-2 3 -1
3
1 6
2 4
6 6
Output
3
4
-1
Explanation
The array is (-2,1,0,3,2,-1). The total is 3; the second query gives 1+0+3=4; the last gives -1.