1672C.md (1601B)
1 Source: https://codeforces.com/problemset/problem/1672/C 2 3 C. Unequal Array 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You are given an array $a$ of length $n$. We define the equality of the array as the number of indices $1 \le i \le n - 1$ such that $a_i = a_{i + 1}$. We are allowed to do the following operation: 22 23 * Select two integers $i$ and $x$ such that $1 \le i \le n - 1$ and $1 \le x \le 10^9$. Then, set $a_i$ and $a_{i + 1}$ to be equal to $x$. 24 25 Find the minimum number of operations needed such that the equality of the array is less than or equal to $1$. 26 27 Input 28 29 Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. The description of the test cases follows. 30 31 The first line of each test case contains an integer $n$ ($2 \le n \le 2 \cdot 10 ^ 5$) — the length of array $a$. 32 33 The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — elements of the array. 34 35 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10 ^ 5$ 36 37 Output 38 39 For each test case, print the minimum number of operations needed. 40 41 Example 42 43 Input 44 45 ``` 46 4 47 48 5 49 50 1 1 1 1 1 51 52 5 53 54 2 1 1 1 2 55 56 6 57 58 1 1 2 3 3 4 59 60 6 61 62 1 2 1 4 5 4 63 ``` 64 65 Output 66 67 ``` 68 2 69 1 70 2 71 0 72 ``` 73 74 Note 75 76 In the first test case, we can select $i=2$ and $x=2$ to form $[1, 2, 2, 1, 1]$. Then, we can select $i=3$ and $x=3$ to form $[1, 2, 3, 3, 1]$. 77 78 In the second test case, we can select $i=3$ and $x=100$ to form $[2, 1, 100, 100, 2]$.