Hw to solve this problem?
Problem: DPOOL04
Any idea?
bro you are given total number of elements of array ‘N’ , array of ‘N’ integers , total number of querie ‘Q’ and ‘Q’ lines of queries containing L1,R1,L2,R2.
what you need to do is to find number of variables of array satisfying the following conditions :-
- Ai = Aj , then this is one of the probable position of the suit.
- L1 <= i <= R1 and L2 <= j <= R2, that is the ith and jth coordinate should lie within the street.
let us take the example :-
7
1 5 2 1 7 2 2
2
1 3 4 5
2 3 5 7
here for first query the value of
L1= 1 , R1 = 3, L2 = 4 and R2=5
you will check elements of array with index in range 1 and 3 and compare with elements of array with index in range 4 and 5 .
here elements in range of 1 and 3 are [ 1 ] ,[ 5 ] and [2]
,
and elements in range of 4 and 5 are [1] and [7]
we can clearly see that element that satisfy the condition is [1]
and pair of indices are (1,4) only one pair
trick:- count total number of elemets in range L1 and R1 that are equal to elements in range L2 AND R2
Can you provide the code?