#P2068. Range Sum Query after Updates

    ID: 15350 Type: Default 1000ms 256MiB

Range Sum Query after Updates

Range Sum Query after Updates

You are given a sequence of length n (\(n \leq 100000\)) with all elements initially equal to 0. You will then perform x update operations (\(x \leq 100000\)), where each operation adds a number to a specified position in the sequence. After all updates, you will be given y queries (\(y \leq 100000\)). Each query asks you to compute the sum of a subarray from index \(L\) to \(R\) (1-indexed).

For an update operation on the \(i^{th}\) position with value \(v\), the update is defined as:

\[ A[i] = A[i] + v \]

For a query given boundary indices \(L\) and \(R\), you need to output:

\[ \sum_{k=L}^{R} A[k] \]

inputFormat

The first line contains three integers: n, x, and y, representing the length of the sequence, the number of update operations, and the number of queries, respectively.

The next x lines each contain two integers: i and v, indicating that you should add the integer v to the ith element of the sequence (1-indexed).

The following y lines each contain two integers: L and R, representing the query range (1-indexed) for which you need to compute the sum.

outputFormat

For each query, output a single line containing the sum of the elements from index L to R inclusive.

sample

5 3 2
1 5
3 2
5 7
1 3
2 5
7

9

</p>