PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000276. Tổng có trọng số theo chỉ số (Weighted 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ó trọng số theo chỉ số (Weighted Prefix)
Weighted Prefix
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer array (possibly negative), compute for each query . The weight is the absolute array index i.
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
10
12
Explanation
2-6+12+4=12; -6+12+4=10; 3·4=12.
Example 2
Input
1 1
-7
1 1
Output
-7
Explanation
There is one element; multiply -7 by weight 1.