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
kalyanavuthu: 2018-08-26 11:45:49

Segment Tree with lazy propogation done the job...! :p

deepak097: 2018-08-23 07:28:28

AC in one go :)

ayusofayush: 2018-08-11 19:43:32

prefect question to implement BIT/Fenwick Tree

Last edit: 2018-08-11 20:04:14
supriyanta: 2018-08-09 22:54:54

Did anyone solve using bitmask?

supriyanta: 2018-08-09 22:53:07

sqrt decomposition or BIT or difference array

kumarmapanip1: 2018-08-07 18:40:10

difference array seems best for this :)

one_piece_: 2018-07-05 03:43:28

damn printf scanf

manjeet_: 2018-07-03 06:50:32

done using priority_queues :-)

jmr99: 2018-06-19 17:09:46

bit does the job simple implementation .

rajcoolaryan: 2018-06-19 12:37:03

5 lines of code and 5 TLE due to cin cout..


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