#P13785. [eJOI 2022] Longest Unfriendly Subsequence
[eJOI 2022] Longest Unfriendly Subsequence
题目描述
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 .
3
5
1 2 1 2 1
7
1 2 3 2 1 2 3
8
1 10 10 1 1 100 100 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
- (3 points):
- (6 points):
- (8 points): The sum of over all test cases doesn't exceed 500
- (10 points):
- (10 points):
- (20 points): The sum of over all test cases doesn't exceed 10000
- (43 points): No additional constraints