#P11446. 「ALFR Round 3」B Swap & Delete

    ID: 12625 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及− 上传者: 标签>贪心洛谷原创O2优化洛谷月赛分类讨论

「ALFR Round 3」B Swap & Delete

Problem Description

Given a sequence of length nn, denoted as a1,a2,a3,…,ana_1, a_2, a_3, \dots, a_n, you need to perform kk operations to make this sequence empty.

Each operation can be one of the following:

  1. Select two indices i,ji, j and swap aia_i and aja_j, satisfying 1≤i<j≤n1 \le i < j \le n.
  2. Select two indices i,ji, j and delete the elements ai,ai+1,…,aja_i, a_{i+1}, \dots, a_j, satisfying 1≤i≤j≤n1 \le i \le j \le n, and ai=aja_i = a_j.

You should output the minimum number of operations kk required.

Input Format

The first line contains a positive integer TT (1≤T≤51 \le T \le 5), indicating the number of test cases.

For each test case:

The first line contains a positive integer nn (1≤n≤1051 \le n \le 10^5), representing the length of the sequence.

The second line contains nn positive integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \le a_i \le 10^9).

Output Format

For each test case, output a single integer kk, indicating the minimum number of operations.

2
5
1 2 3 2 3
3
1000000000 1000000000 99999999
2
2

Hint

Subtask Score Constraints
11 1010 n≤3n \le 3
22 2020 n≤10n \le 10
33 ai≤2a_i \le 2
44 1010 All aia_i are guaranteed to be equal
55 4040 -

For all the tests, 1≤T≤51 \le T \le 5, 1≤n≤1051 \le n \le 10^5, 0≤ai≤1090 \le a_i \le 10^9.