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
___Durgesh___: 2015-08-25 09:41:53

learnt a new approach :)

SANDEEP KUMAR: 2015-08-21 20:20:58

Ac in one go..Used prefix sum..O(n)

screw_1011: 2015-08-20 07:11:55

And when you think of segtrees and BIT , but oops, suddenly a 15 line code gives you AC :) O(n) :P

SangKuan: 2015-08-18 04:11:28

ac with BIT,want to know the O(n) method

anuveshkothari: 2015-07-31 20:27:35

learned something new about updating the array..

sai krishna: 2015-07-28 06:29:03

Got AC with Both BIT and Segment tree+Lazy Propogation

:.Mohib.:: 2015-07-26 17:24:46

Nice que...!!

sumit2893: 2015-06-16 03:31:46

This can help..https://kartikkukreja.wordpress.com/2013/12/02/range-updates-with-bit-fenwick-tree/

shuks: 2015-06-03 13:56:15

How to solve using BIT?
I solved without BIT in O(n)

Arpan Mukherjee: 2015-05-21 22:02:10

My 1st BIT :) finally AC :) learnt a new DS :)


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