[Solution] Diverse Segments Codeforces Solution | Codeforces Problem Solution 2022
You are given an array of integers. Also you are given subsegments of that array. The left and the right endpoints of the -th segment are and respectively.
You are allowed to make no more than one operation. In that operation you choose any subsegment of the array and replace each value on this segment with any integer (you are also allowed to keep elements the same).
You have to apply this operation so that for the given segments, the elements on each segment are distinct. More formally, for each all elements should be distinct.
You don't want to use the operation on a big segment, so you have to find the smallest length of a segment, so that you can apply the operation to this segment and meet the above-mentioned conditions. If it is not needed to use this operation, the answer is .
The input consists of multiple test cases. The first line contains a single integer () — the number of test cases. Description of the test cases follows.
The first line of each test case contains two integers and () — the size of the array and the number of segments respectively.
The next line contains integers () — the elements of .
Each of the next lines contains two integers , () — the left and the right endpoints of the -th segment.
It's guaranteed that the sum of and the sum of over all test cases does not exceed .
For each test case output a single integer — the smallest length of a segment you can apply an operation on making the elements on all given segments distinct. If it is not needed to use the operation, output .
No comments:
Post a Comment