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
hashem sllat: 2016-02-27 13:44:14

TLE with segment tree + lazy propogation

lhagvaasuren: 2016-02-19 09:38:19

Small tip: Use fast I/O guys.

minhthai: 2016-01-17 04:39:31

java + O(n) and still TLE :(
Anyway, learned something new, sweet!

SUBHAJIT GORAI: 2015-12-20 19:12:16

simple O(n) solution ...no need of segment tree ....notice =>no query in between the updates ...

Lai Manh Tuan: 2015-11-01 20:56:04

got AC with fast IO + segment tree (lazy propagation)

Last edit: 2015-11-01 20:56:22
Abhinandan Agarwal: 2015-10-19 18:32:51

BIT->0.10s
O(n)->0.02s

Dhiresh: 2015-09-14 07:09:02

Using prinf scanf instead of cin cout saved me from TLE.
PS: used BIT

Jens Stimpfle: 2015-08-31 00:41:33

How to go real fast? I've used BIT and fast input, but can't get below 0.06s.

abhinav vinci: 2015-08-27 07:11:16

O(n)- using prefix sum
note -- if using cin,cout
use this line to stop 'flushing',this is better than scanf,printf
std::ios::sync_with_stdio(false);

Last edit: 2015-08-27 07:13:19
Shashank Tiwari: 2015-08-26 16:23:48

Got 10 Wa just because in each test case i did not initialize BIT with zeroes again . Make sure u r not getting Wa because of that


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