PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000277. Tổng trọng số theo vị trí tương đối (Relative Weighted Range 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 trọng số theo vị trí tương đối (Relative Weighted Range Sum)
Relative Weighted Range Sum
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer array (possibly negative), compute for each query . The first element of the range has weight 1, the next weight 2, and so on.
Input
First line: . Second line: integers . Next lines: .
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
12
8
4
Explanation
2-6+12+4=12; -3+8+3=8; 1·4=4.
Example 2
Input
1 1
-7
1 1
Output
-7
Explanation
There is one element; multiply -7 by weight 1.