PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000294. Tổng tích mọi cặp trong đoạn (Sum of Pair Products in a Range)
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 tích mọi cặp trong đoạn (Sum of Pair Products in a Range)
Sum of Pair Products in a Range
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
For each inclusive range , compute . Count each unordered pair of distinct indices once. A singleton gives zero. Print the exact integer, without a modulus.
Input
First line: . Second line: array elements. Each of the next lines contains .
Output
Print each answer on its own line.
Subtasks
- Subtask 1 (20 points): , , . Additionally: .
- Subtask 2 (30 points): , , . Additionally: .
- Subtask 3 (50 points): , , .
Example 1
Input
3 2
1 2 3
1 3
2 2
Output
11
0
Explanation
The three pairs give 2+3+6=11. A singleton has no pair.
Example 2
Input
3 2
-3 2 -1
1 3
1 2
Output
-5
-6
Explanation
The three products -6, 3, -2 sum to -5; the second range gives -6.