아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Longest Unfriendly Subsequence

시간 제한1초메모리 제한1024 MB

요약
고른 원소 중 인덱스 차이가 2 이하인 어떤 두 원소도 서로 다른, 수열 a의 가장 긴 부분수열의 길이를 구한다.
난이도

보통10점 중 6점

유형
그리디, 배열, 동적 계획법
정답자
아직 제출이 없습니다

문제

Let's call sequence b_1,b_2,…,b_mb\_1 , b\_2 , \dots , b\_m unfriendly, if the following condition holds:

  • If 1≤i<j≤m1 ≤ i < j ≤ m and j−i≤2j - i ≤ 2, then b_i≠b_jb\_i ≠ b\_j.

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

You are given a sequence a_1,a_2,…,a_na\_1 , a\_2 ,…, a\_n. Find the length of its longest unfriendly subsequence.

A sequence cc is a subsequence of a sequence dd if cc can be obtained from dd by deletion of several (possibly, zero or all) elements. For example, (1,3,5)(1, 3, 5) is a subsequence of (1,2,3,4,5)(1, 2, 3, 4, 5) while (3,1)(3, 1) is not.

입력

The first line contains a single integer tt (1≤t≤1051 ≤ t ≤ 10^5) - the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 ≤ n ≤ 2 ⋅ 10^5) - the length of the sequence.

The second line of each test case contains nn integers a_1,a_2,…,a_na\_1 , a\_2 , \dots , a\_n (1≤a_i≤1091 ≤ a\_i ≤ 10^9) - the elements of the sequence aa.

It's guaranteed that the sum of nn over all test cases doesn't exceed 2⋅1052 ⋅ 10^5.

출력

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

힌트

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

In the second test case, the longest unfriendly subsequence is (1,2,3,1,2,3)(1, 2, 3, 1, 2, 3). It's clear that the subsequence which consists of the whole sequence is not unfriendly, so the answer is 66.

In the third test case, the longest unfriendly subsequence is (1,10,100,1)(1, 10, 100, 1).

예제1

  1. 예제 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
    
    예상 출력
    2
    6
    4