Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Match the Range

By IamHot · Limits 1s, 512 MB

Well, I will not waste your time and go straight to the problem.

You are given an array A of numbers. And some queries. Each query consists of two ranges. You need to find out if those two ranges are similar or not. You are given a function to figure out if two ranges are same or not.

function IsSame(x1, y1, x2, y2)
    Array1 = []
    Array2 = []

    For i = x1 to y1
        Array1.push(A[i])   
    end For 

    For i = x2 to y2
        Array2.push(A[i])   
    end For 

   NewArray1 = sort the elements inside Array1
   NewArray2 = sort the elements inside Array2

  return (NewArray1 equals NewArray2)
end function

Input

The first line contains two integer N - number of elements in the array and Q - number of queries. Next line contains N integers denoting the ith element of the array A.

Next there are Q queries with four integers which is described above.

  • 1 ≤ N, Q ≤ 105
  • 1 ≤ A[i] ≤ 105
  • 1 ≤ x1, y1, x2, y2 ≤ N

Output

For each query, use the function given above and if the function returns true value print “Yes” otherwise print “No” without quote .

Sample

InputOutput
6 3
1 2 3 1 2 3
1 3 4 6
2 4 3 5
1 2 2 3
Yes
Yes
No

Discussion

Statistics


48% Solution Ratio

sakibalaminEarliest, 11M ago

sakibalaminFastest, 0.0s

Alamin_justLightest, 1.2 MB

subhashis_cseShortest, 559B

Submit

Login to submit

Related Contests

Stamford University Bangladesh Summer Contest 2019 Ended at 2019-05-03 07:00:00 +0000 UTC
Replay of Stamford University Bangladesh Summer Contest 2019 Ended at 2019-05-03 18:00:00 +0000 UTC