Segments maybe Super segments

4

5 votes
Graphs, Algorithms, Depth First Search
Problem

You have an array a of integers between 0 and 106. Initially, you do not know exactly the value of any element of the array, but you know that the length of the array is n. Also, you are given m segments of the array l r x, where l is the left bound of the segment, r is the right bound of the segment, x is the sum of the segment. Then You are given q queries ql qr. For every query, you need to print the sum of elements of the array a on [ql,qr] interval, if it is impossible to print 1.

 

Input

 

- First line will contain T, number of testcases. 

- In first line of testcase you are given n, m q.

- In next m lines of testcase you are given information about array l, r, x.

- in next q lines of testcase you are given queries in form ql, qr.

 

Output

 

-For each query, you need to print the answer in a single line.

 

Constraints

- 1T200

- 2n,m,q2105

- 1l,r,ql,qrn

- 0x106

It is guaranteed that the sum of n overall test cases does not exceed 2105

It is guaranteed that the sum of m overall test cases does not exceed 2105

It is guaranteed that the sum of q overall test cases does not exceed 2105
 

Sample Input
1
3 2 3
1 2 3
3 3 2
1 3
1 2
1 1
Sample Output
5
3
-1
Time Limit: 1
Memory Limit: 512
Source Limit:
Explanation

the sum for segment [1, 2] is 3 and sum for segment [3, 3] is 2. So the sum for first query [1, 3] is 5.

 

sum for segment [1, 2] is given it is 3

 

sum for segment [1, 2] is unknown since a1 can be any number from 0 to 3

Editor Image

?