
Range [X,Y] contains range [A,B] if 'X' <= 'A' and 'Y' >= 'B'.
The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains an integer ‘N’ representing the number of integers in the array, ‘RANGES’.
The next ‘N’ lines of each test case contain two space-separated integers, ‘Ai’ and ‘Bi’ representing the range: [Ai, Bi].
For each test case, return a list of two arrays, ‘RESULT’ where for each range ‘RESULT[ 0 ]’ is an array of size ‘N’ that stores the count of ranges a range contains and ‘RESULT[ 1 ]’ is an array of size ‘N’ that stores the count of ranges a range is contained by.
The output of each test case will be printed in a separate line.
1 <= T <= 5
1 <= N <= 2000
1 <= Ai < Bi <= 10 ^ 6
All ranges are distinct.
Where ‘T’ is the number of test cases, ‘N’ is the number of ranges in the array, ‘RANGES’ and ‘Ai’ and ‘Bi’ are the integers representing the ‘i’th range: [Ai, Bi] in array ‘RANGES’.
Time limit: 1 second.
You do not need to print anything, it has already been taken care of. Just implement the given function.
The idea is to use the brute force approach. For each range in the ‘RANGES’, we will check all the other ranges whether it contains some other range and if some other range contains it.
If the given array is sorted in ascending order by the start value of the ranges (If the start values of any two ranges are the same, then sort them in decreasing order of their end values), we can draw the following observations:
To efficiently count the number of ranges in the above cases, we can either use a policy-based data structure in C++ like ‘ordered_set’ or a widely used data structure like Binary Indexed Trees. As both of them offer to count the number of items strictly smaller than an item ‘K’ in logarithmic time.
Given below is the implementation using ‘ordered_set’.
Description of ‘comp’ function
This function will take two parameters:
bool comp(A1, A2):