Consider two arrays A and B. The element at index i in array A is associated with element at index i in array B. We can think of them as a pair. We have some queries q in form of (a, b). We need to find the count of all such elements for which A[i] > a and B[i] > b.
Constraints -
n (size of array) <= 10^5
q (count of queries) <= 10^5
Example -
A = [1, 3, 6, 7, 2]
B = [10, 7, 2, 6, 4]
q = [(2, 6), (3, 9), (0, 1)]
Output -
[1, 0, 5]
Explanation-
For query (2, 6) there is only one entity such that A[i] > 2 and B[i] > 6. For the first condition A[i] > 2 we have three candidates - 3, 6, 7 but based on second condition B[i] > 6 for these candidates there is only one answer that is candidate with value 3 in first array (3, 7).
I have tried the brute force approach of linear search but that leads to TLE.