
Let ‘N’ = 3 and ‘METEORITES’ = [[1, 2], [2, 3], [6, 1]].
The position and size of each meteorite are: </br>
‘Meteorite1’: At 1 position and size of 2.
‘Meteorite2’: At 2 position and size of 3.
‘Meteorite3’: At 6 position and size of 1.

So when the first meteorite falls maximum height till now is 2.
When the second meteorite falls maximum height till now is 5.
When the third meteorite falls maximum height till now is 5.
The first line of input contains an integer ‘T’ which denotes the number of test cases or queries to be run. Then the test cases follow.
The first line of each test case contains an integer ‘N’ representing the number of meteorites.
The next ‘N’ line of each test case contains two single space-separated integers ‘X’ and ‘SIZE’ representing the leftmost X-coordinate and size of the meteorites respectively.
For each test case, print a single line containing the current highest height of any meteorite after each meteorite falls from space.
The output of each test case will be printed in a separate line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= ‘T’ <= 10
1 <= ‘N’ <= 1000
1 <= ‘X’ <= 100000
1 <= ‘SIZE’ <= 10000
Where ‘T’ denotes the total number of test cases, ‘N’ represents the number of meteorites,’ X’ denotes the leftmost X-coordinate of the current meteorite and ‘SIZE’ represents the size of the current meteorite.
Time Limit: 1 second
We are finding height with the help of the ‘QUERY’ function and then updating the heights with the help of the ‘UPDATE’ function. These functions take O(N) time. And we know we have a data structure that works on queries and updates on intervals. With the help of segment tree data structure we can find the maximum height due to the current meteorite with the help of ‘QUERY’ function in O(log(N)) time and we can update the ‘TEMP_HEIGHT’ array/list with the help of the ‘UPDATE’ function in also O(log(N)) time.
When we want to update an interval all at once, we need to use lazy propagation so that our algorithm works fast.
You can learn about Segment tree and Lazy propagation from here:
https://www.codingninjas.com/free-content/competitive-programming-course/content/segment-tree
https://www.codingninjas.com/blog/2020/08/29/learn-to-build-a-segment-tree/
Here is the algorithm:
The algorithm is the same as the above solution algorithm but different in only the ‘QUERY’ and ‘UPDATE’ functions. Here we implement these functions with the help of a segment tree data structure.
‘OUERY(‘L1’, ‘R1’)’.
‘QUERY_HELPER(‘INDEX’ , ‘START’, ’END’, ‘L1’, ‘R1’)
UPDATE(‘L1’, ‘R1’ , ‘CURR_MAX_HEIGHT’).
UPDATE_HELPER(‘INDEX’, ‘START’, ‘END’ , ‘L1’, ‘R1’ , ‘CURR_MAX_HEIGHT’).