UPDATEIT - Update the array !


You have an array containing n elements initially all 0. You need to do a number of update operations on it. In each update you specify l, r and val which are the starting index, ending index and value to be added. After each update, you add the 'val' to all elements from index l to r. After 'u' updates are over, there will be q queries each containing an index for which you have to print the element at that index.

Input

First line consists of t, the number of test cases. (1 <= t <= 10)

Each test case consists of "n u", number of elements in the array and the number of update operations, in the first line (1 <= n <= 10000 and 1 <= u <= 100000)

Then follow u lines each of the format "l r val" (0 <= l, r < n, 0 <= val <=10000)

Next line contains q, the number of queries. (1 <= q <= 10000)

Next q lines contain an index (0 <= index < n)

Output

For each test case, output the answers to the corresponding queries in separate lines.

Example

Input:
1
5 3
0 1 7
2 4 6
1 3 2
3
0
3
4

Output:
7
8
6

hide comments
harsh3005: 2019-11-10 14:42:05

use printf scanf as cin cout slows you down!::-)

shogun420: 2019-10-09 09:38:49

AC in one go!!

Last edit: 2019-10-09 09:39:15
emtiaz_001: 2019-09-25 22:31:36

just use your idea to get red of TLE

ab_biswas09: 2019-08-10 07:18:44

Difference Array !!

jessepinkman90: 2019-06-13 14:25:20

use scanf and printf

mahbubkuet08: 2019-03-17 10:04:09

BIT took 0.13 secs
Diff Array took 0.10 secs

masterchef2209: 2019-01-08 12:00:04

learned difference array use

Last edit: 2019-01-08 12:00:12
ankitpriyarup: 2018-12-20 16:24:04

Simply use a difference array :)

pigpork: 2018-12-15 06:36:10

AC in no goes! :)

nuhash_40: 2018-10-14 23:43:03

ac in one go :) done with normal cumulative sum array


Added by:Pandian
Date:2013-10-15
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own