a guest Jul 6th, 2017 129 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- Our dear Spiderman has fallen in love with Mary Jane and is planning to propose her tonight.
- He has thought of a wonderful way which would require the entire evening and thus can't be disturbed.
- As usual, a problem has occurred and this time Spiderman wants your help to solve the problem.
- Can you help him?
- You will be given an array A of size N and Q queries.
- In every query, you will be given 4 integers E,F,G and H.
- Consider every permutation of subarray A[E] to A[F], similarly consider every permutation of subarray A[G] to A[H].
- You have to tell whether there exists any permutation of both subarrays such that, the number of positions where A[i]!=A[j], where E <= i <= F and G <= j <= H is atmost 1.Both permutations can be different.Every query is independent.
- The equality F-E+1 = H-G+1 always holds.
- First line contains T, the number of test cases.
- For every test case, the first line contains two integers N, the size of array and Q, the number of queries respectively.
- The next line contains N space separated integers.
- The next Q lines contains four integers E,F,G and H respectively, describing the query, as stated above.
- For each query, output the required answer ("YES" or "NO") in a new line.
- 1 <= T <= 5
- 1 <= N,Q <= 105
- 1 <= A[i] <= 105
- 1 <= E,G <=F,H <= N
- Sample Test Case
- 8 2
- 1 2 3 4 1 1 2 3
- 1 2 3 4
- 1 4 5 8
- For query 1 2 3 4 there exists no such permutation, thus answer is NO.
- For query 1 4 5 8, one such permutation is
- 1 2 3 4
- 1 2 3 1
- Here the difference is 1, thus answer is YES.
RAW Paste Data