PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000279. Tổng của các tổng tiền tố (Prefix of Prefix)
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ủa các tổng tiền tố (Prefix of Prefix)
Prefix of Prefix
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer array , define . For each query , compute . Every prefix starts at index 1, not at .
Input
First line: . Second line: integers . Each of the next lines contains two integers .
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 3
2 -3 4 1
1 4
2 4
3 3
Output
8
6
3
Explanation
P=(2,-1,3,4). The sums are 2-1+3+4=8; -1+3+4=6; 3.
Example 2
Input
1 1
-5
1 1
Output
-5
Explanation
P1=-5.