

For the given if N = ‘5’, ‘SWEET’ = [1,3,6,7,2] and ‘EXPIRY = [10,7,2,6,4].
And the query is ‘X’=2 and ‘Y’ =6 ,then the number of sweets satisfying the condition is only 1 (having sweetness 3 and expiry date 7).
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains two integers, ‘N’ and ‘Q’, representing the number of sweets and the number of queries.
The second line of each test case contains a ‘SWEET’ array.
The third line contains the ‘EXPIRY’ array.
The next ‘Q’ line contains two integers ‘X’ and ‘Y’, for the respective query.
For each test case, print ‘Q’ values corresponding to the answer for each query.
Print the output of each test case 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 <= 100000.
1 <= Q <= 100000.
1 <= SWEET[i] <=100000
1 <= EXPIRY[i] <= 100000
Time limit: 1 sec
In this approach, for each query, we will iterate over all the sweets and check if that sweet satisfies both the condition or not. If it does, we will increment our counter.
In this approach, first, we will sort the values of ‘CHOCOLATES’ and ‘QUERIES’ in descending order. After that, we will prepare a Binary Indexed Tree which stores the value in sorted order, and operations like insertion and index position is done logN time. So we will build a BIT to store the values of expiry date in the sorted order.
So we will start from the sweet with the largest sweetness level and insert the corresponding expiry date value and while answering queries, we will use the index position to calculate the number of elements in the BIT whose value is less than or equal to the queried expiry date.