#C11150. Range Updates and Queries
Range Updates and Queries
Range Updates and Queries
You are given an array of n integers. Then, you are provided with m range update operations. Each update operation is described by three integers, l, r and v, meaning that you should add v to each element in the array with indices from l to r (both inclusive). After performing all the updates, you must answer q queries. Each query is a single integer p asking for the value at position p in the updated array.
Input Constraints: You may assume that the array indices are 1-based. The operations and queries are performed sequentially.
Mathematical Formulation:
If the initial array is \(A = [a_1, a_2, \dots, a_n]\) and each update is defined by \((l_i, r_i, v_i)\) for \(i = 1,2,\dots,m\), then the final array \(A'\) is given by:
[ a'j = a_j + \sum{i ; \text{s.t.} ; l_i \le j \le r_i} v_i, \quad 1 \le j \le n. ]
Your task is to process the updates and then answer the queries by outputting the corresponding updated value.
inputFormat
The input is given from the standard input in the following format:
- First line contains two integers
n
andm
separated by a space. - Second line contains
n
integers representing the initial array. - The next
m
lines each contain three integersl
,r
andv
for each update operation. - The next line contains an integer
q
, the number of queries. - The next
q
lines each contain a single integer representing the query index.
outputFormat
For each query, output the updated value of the array at the given position on a new line, using standard output.
## sample5 3
1 2 3 4 5
1 3 2
2 4 1
1 5 -1
2
1
5
2
4
</p>