PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000290. Tổng bình phương vị trí tương đối (Relative Quadratic Weighted Sum)
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 bình phương vị trí tương đối (Relative Quadratic Weighted Sum)
Relative Quadratic Weighted Sum
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
For each inclusive query , compute in the given array. The first element of the queried segment has weight 1.
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: all queries satisfy .
- Subtask 3 (50 points): , , .
Example 1
Input
3 2
2 -1 3
1 3
2 3
Output
25
11
Explanation
First: . Second: .
Example 2
Input
1 1
-5
1 1
Output
-5
Explanation
The single element has weight 1, so the answer is -5.