PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000278. Tổng trọng số đa thức (Polynomial Moment 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 trọng số đa thức (Polynomial Moment Prefix)
Polynomial Moment 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 depends on the absolute index i, not the start of the range.
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
78
66
72
Explanation
The weights are 6,11,18,27. The answers are 12-33+72+27=78; -33+72+27=66; 18·4=72.
Example 2
Input
1 1
-7
1 1
Output
-42
Explanation
There is one element; multiply -7 by weight 6.