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
Ouditchya Sinha: 2013-10-24 07:56:47

@Mitch Schwartz : Thank you for your reply, I optimized my code to get AC in 0.22s now. Will keep trying... :)

Mitch Schwartz: 2013-10-23 15:42:51

@Ouditchya @Isis: Ok, I submitted a "normal I/O" version of my code and got 1.30s, so you can compare in that way.

Mahesh Mishra: 2013-10-23 13:57:17

@Mitch Schartz.. I had used the best possible algo for this problem with fast I/O but still got 0.22 and you are at 0.11 .. I just wonder how do you do it.. Can you give some hints..

Ouditchya Sinha: 2013-10-23 11:26:13

@Mitch Schwartz : Sir, great job again, your solution is too fast. Can you give me some hint? I'm using Binary Indexed Tree with very Fast I/O but I can't go below 0.34s. Thank you. :)

SWOOSH!!!: 2013-10-23 10:23:37

Getting SIGSEGV in submission #10328019...@Pandian can you please check???

Mahesh Mishra: 2013-10-21 16:36:33

This is very cruel for java users...
Exactly the same algo in java times out and gets AC in 0.22 in C++..
Also there is no need of segment tree.. make some manipulations with array indices and you will get it..

[Lakshman]: 2013-10-21 13:32:57

@Deepak Malik I don't know why you are getting TLE but I got AC using Segment tree.

PS: Use fast I/O method if you are using segment Tree.

Last edit: 2013-10-21 13:39:03
Pandian: 2013-10-21 11:43:04

@Deepak Malik : You don't need segment tree !

Anirudh V Raja: 2013-10-21 08:00:34

Nice and simple question :)

Pandian: 2013-10-21 07:04:20

@Bhavik : Seeing the constraints in the problem, obviously yes !


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