#K2851. Array Increment Operations
Array Increment Operations
Array Increment Operations
You are given an array of ( n ) integers initialized in increasing order such that ( A[i] = i+1 ) for ( i=0,1,\ldots,n-1 ). You will perform ( m ) operations on this array. In the ( j )-th operation, you are given an index ( a_j ) (1-indexed) and a value ( b_j ); you must add ( b_j ) to the element at position ( a_j ) (i.e. update ( A[a_j-1] = A[a_j-1] + b_j )). After performing all operations, you will answer ( q ) queries. In each query you are provided with an index ( x ) (1-indexed) and you must print the final value of ( A[x-1] ).
Example:
For ( n=5, m=3 ) and operations: indices [2, 3, 5] with additions [10, 20, 5], the initial array is ( [1,2,3,4,5] ). After the operations, the array becomes ( [1,12,23,4,10] ) and if the queries are indices [1,2,5], the answers will be [1,12,10].
inputFormat
The input is given from standard input (stdin) and consists of four lines:
-
The first line contains three space-separated integers ( n ), ( m ), and ( q ) representing the number of elements, the number of operations, and the number of queries, respectively.
-
The second line contains ( m ) space-separated integers representing the indices ( a_1, a_2, \ldots, a_m ) (1-indexed) on which operations are applied. If ( m = 0 ), this line will be empty.
-
The third line contains ( m ) space-separated integers representing the values ( b_1, b_2, \ldots, b_m ) to be added. If ( m = 0 ), this line will be empty.
-
The fourth line contains ( q ) space-separated integers representing the query indices (1-indexed) whose final values are to be determined.
outputFormat
Print to standard output (stdout) a single line containing ( q ) space-separated integers, where each integer is the final value of the array at the queried index after all operations have been performed.## sample
5 3 3
2 3 5
10 20 5
1 2 5
1 12 10
</p>