#P1922F. Replace on Segment
Replace on Segment
No submission language available for this problem.
Description
You are given an array , where each element is an integer from to .
You can perform the following operation with it any number of times:
- choose three integers , and such that , and each element such that is different from . Then, for each , replace with .
In other words, you choose a subsegment of the array and an integer from to which does not appear in that subsegment, and replace every element in the subsegment with that chosen integer.
Your goal is to make all elements in the array equal. What is the minimum number of operations that you have to perform?
The first line contains one integer () — the number of test cases.
Each test case consists of two lines:
- the first line contains two integers and ();
- the second line contains integers ().
Additional constraint on the input: the sum of over all test cases does not exceed .
For each test case, print one integer — the minimum number of operations you have to perform.
Input
The first line contains one integer () — the number of test cases.
Each test case consists of two lines:
- the first line contains two integers and ();
- the second line contains integers ().
Additional constraint on the input: the sum of over all test cases does not exceed .
Output
For each test case, print one integer — the minimum number of operations you have to perform.