#DSU0000085. Chia thành các khối (Into Blocks, Easy Version)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chia thành các khối (Into Blocks, Easy Version)
Into Blocks (Easy Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
An integer sequence is nice if every value appears in exactly one contiguous block. For example, is nice, while is not.
You may change values to make the array nice, with the restriction that all positions having the same original value must receive the same final value. A value appearing originally in multiple places cannot be changed into different values at those places.
The cost is the number of positions whose final value differs from the original. Find the smallest possible cost.
This version has no update operations; only the original array is considered.
Input
The first line contains . The next line contains the elements of the array.
Output
Print the minimum number of array elements that must change.
Subtasks
- Subtask 1 (20 points): , .
- Subtask 2 (30 points): , .
- Subtask 3 (50 points): , .
Example
Input
5
3 7 3 7 3
Output
2
Explanation
Values and interleave and must end up in one block. Keep the three s and change both s to ; the optimal cost is .