#C6505. Village Population Update Queries

    ID: 50273 Type: Default 1000ms 256MiB

Village Population Update Queries

Village Population Update Queries

You are given a series of test cases describing villages with initial populations. In each test case, you will be provided a list of N village populations. Then a number of update operations are performed; each update is specified by three integers \(L\), \(R\), and \(P\) indicating that for every village index \(i\) such that \(L \leq i \leq R\), the population increases by \(P\). Finally, a sequence of queries is given, where each query asks for the updated population of the village at a specific index.

Your task is to process all updates and then output, for each query, the final population of the corresponding village. All indices are 0-indexed.

Input Format:

  • The first line contains an integer \(T\) representing the number of test cases.
  • For each test case:
    • The first line contains an integer \(N\), the number of villages.
    • The second line contains \(N\) space-separated integers representing the initial populations.
    • The third line contains an integer \(M\) representing the number of updates.
    • The next \(M\) lines each contain three space-separated integers \(L\), \(R\), and \(P\), describing an update operation.
    • The following line contains an integer \(Q\) representing the number of queries.
    • The last line of the test case contains \(Q\) space-separated integers, each an index to be queried.

Constraints:

  • \(0 \leq N, M, Q \leq 10^5\) (depending on the test file).
  • \(0 \leq L \leq R \lt N\).

Output Format:

For each query in each test case, output the updated population on a new line in the order of appearance.

inputFormat

The input is read from standard input (stdin) and has the following format:

T
N
pop1 pop2 ... popN
M
L1 R1 P1
L2 R2 P2
... (M updates)
Q
q1 q2 ... qQ
... (repeat the above for each test case)

Where:
- \(T\) is the number of test cases.
- For each test case, \(N\) is the number of villages, followed by \(N\) integers representing the initial populations.
- \(M\) is the number of update operations, followed by \(M\) lines each containing three integers \(L\), \(R\), and \(P\).
- \(Q\) is the number of queries, followed by \(Q\) integers where each integer is the 0-indexed village to query.

outputFormat

For each query, output the final population of the corresponding village on a new line in the order of appearance.

## sample
1
5
10 20 30 40 50
2
1 3 10
0 2 5
3
0 2 4
15

45 50

</p>