logo AlgoBeat OnlineJudge
登录 注册

#213884. [eJOI 2022] Longest Unfriendly Subsequence

内存限制:2048 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Let's call sequence unfriendly, if the following condition holds:

  • If and , then .

In other words, a sequence is unfriendly if any two elements on the distance at most 2 are different.

You are given a sequence . Find the length of its longest unfriendly subsequence.

A sequence is a subsequence of a sequence if can be obtained from by deletion of several (possibly, zero or all) elements. For example, is a subsequence of while is not.

输入格式

The first line contains a single integer () - the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer () - the length of the sequence.

The second line of each test case contains integers () - the elements of the sequence .

It's guaranteed that the sum of over all test cases doesn't exceed .

输出格式

For each test case, output a single integer - the length of the longest unfriendly subsequence of .

样例

样例输入 1

3
5
1 2 1 2 1
7
1 2 3 2 1 2 3
8
1 10 10 1 1 100 100 1

样例输出 1

2
6
4

数据范围与提示

Note

In the first test case, the longest unfriendly subsequences are and . The subsequence , for example, is not unfriendly, as its 1-st and 3-rd elements are equal.

In the second test case, the longest unfriendly subsequence is . It's clear that the subsequence which consists of the whole sequence is not unfriendly, so the answer is 6.

In the third test case, the longest unfriendly subsequence is .

Scoring

  1. (3 points):
  2. (6 points):
  3. (8 points): The sum of over all test cases doesn't exceed 500
  4. (10 points):
  5. (10 points):
  6. (20 points): The sum of over all test cases doesn't exceed 10000
  7. (43 points): No additional constraints