#FT0000013. Cập nhật dãy số (Update the Array)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cập nhật dãy số (Update the Array)
Update the Array
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of elements indexed through , with all values initially zero. First perform range-add updates, and only afterward answer a set of queries.
Each update is specified by l r v and adds to every element from index through index , including both endpoints. Updates may overlap, in which case their contributions accumulate.
Once all updates have finished, there are queries. Each query supplies one index and asks for the final value of . No additional updates occur between these queries. Both update and query indices are zero-based.
Input
- Line 1:
n ugives array length and range-update count. - Next lines: each contains
l r v; add to every element in the inclusive zero-based interval . - Next line:
q, the number of point queries. - Last lines: each contains one zero-based position
pto query after every update.
Output
Print exactly lines. Line gives the final value at the position requested in query , after all range additions.
Subtasks
Subtask 1 (20 points):
- .
- .
- .
- .
- .
- .
Subtask 2 (30 points):
- .
- .
- .
- .
- .
- .
Subtask 3 (50 points):
- .
- .
- .
- .
- .
- .
Examples
Input
5 3
0 1 7
2 4 6
1 3 2
3
0
3
4
Output
7
8
6
Explanation
There are elements. The initial values are [0, 0, 0, 0, 0].
-
Command 1 —
0 1 7: Add to , giving array[7, 7, 0, 0, 0]. -
Command 2 —
2 4 6: Add to , giving array[7, 7, 6, 6, 6]. -
Command 3 —
1 3 2: Add to , giving array[7, 9, 8, 8, 6]. -
Command 4 —
0: After all additions, index contains ; print7. -
Command 5 —
3: After all additions, index contains ; print8. -
Command 6 —
4: After all additions, index contains ; print6.
The final point-query answers are printed on separate lines in the order requested.