PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CT0000058. Tổng có trọng số (Weighted Sum)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Đang đọc
Tổng có trọng số (Weighted Sum)
Weighted Sum
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer sequence . There are queries. Each query gives , where and .
For , compute
For , compute
Answer all queries in order.
Input
The first line contains .
The second line contains .
Each of the next lines contains .
Output
Print lines. Line contains the answer to query .
Subtasks
- Subtask 1 (30%): , .
- Subtask 2 (30%): every query has , , .
- Subtask 3 (40%): , .
Every answer fits in a signed 64-bit integer.
Examples
Example 1
Input
5 3
2 1 3 4 2
2 5 1
2 5 2
1 3 1
Output
27
23
13
Explanation
The first query is . The second query uses reversed weights.
Example 2
Input
4 3
-1 2 -3 4
1 4 1
1 4 2
2 3 1
Output
10
0
-4
Explanation
Array values may be negative; weights are still determined by positions inside the queried segment.
Example 3
Input
1 2
7
1 1 1
1 1 2
Output
7
7
Explanation
For a one-element segment, both query types assign weight .
Liên quan
Trong các cuộc thi sau: