We are given two unsorted arrays. We have to find the number of pairs such that for each pair A[i] > X and B[i] > Y. We will have to process 1 million such queries where each query will have different X and Y given. The length of the array will also be up to 1 million.
Constraints :
1 <=A[i],B[i],X,Y <=10^9 1<= A.size, B.size, Number of Queries <= 10^6
For ex :
A = [7,2,10,15,12,9]
B = [10,8,5,3,4,7]
Queries :
X Y o/p
9 3 2 (As we have 2 pairs which satisfy above condition (10,5), (12,4))
6 4 3 (As we have 3 pairs which satisfy above condition (7,10), (10,5), (9,7))
Is there any better approach than brute force as we have 1 million such queries?