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
JordanBelfort: 2014-01-01 04:23:02

Bingo with bit..:)

Vipul Pandey: 2013-12-31 23:39:19

Use BIT instead of segment tree.

[Lakshman]: 2013-12-30 20:12:25

@Sinchan use BIT binery index tree.

shinchan: 2013-12-30 18:10:54

can anyone give a hint to solve this without segment tree?

Saimadhav Heblikar: 2013-12-15 18:49:03

Is segmented tree the only way on this problem?

NISHANT RAJ: 2013-12-10 18:22:48

A similar prob.
http://www.spoj.com/problems/HAYBALE/

Last edit: 2014-02-19 07:10:51
Chandan Mittal: 2013-12-09 20:40:43

my first BIT :)

Nick: 2013-11-22 14:20:19

Help me please, give more test case..
I am getting WA. Please..

Raushan Kumar: 2013-11-04 14:48:00

solvd without segment tree:D

Martijn Muijsers: 2013-10-24 13:09:22

Not another one of these...


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