CF1479B1.Painting the Array I
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The only difference between the two versions is that this version asks the maximal possible answer.
Homer likes arrays a lot. Today he is painting an array a1,a2,…,an with two kinds of colors, white and black. A painting assignment for a1,a2,…,an is described by an array b1,b2,…,bn that bi indicates the color of ai ( 0 for white and 1 for black).
According to a painting assignment b1,b2,…,bn , the array a is split into two new arrays a(0) and a(1) , where a(0) is the sub-sequence of all white elements in a and a(1) is the sub-sequence of all black elements in a . For example, if a=[1,2,3,4,5,6] and b=[0,1,0,1,0,0] , then a(0)=[1,3,5,6] and a(1)=[2,4] .
The number of segments in an array c1,c2,…,ck , denoted seg(c) , is the number of elements if we merge all adjacent elements with the same value in c . For example, the number of segments in [1,1,2,2,3,3,3,2] is 4 , because the array will become [1,2,3,2] after merging adjacent elements with the same value. Especially, the number of segments in an empty array is 0 .
Homer wants to find a painting assignment b , according to which the number of segments in both a(0) and a(1) , i.e. seg(a(0))+seg(a(1)) , is as large as possible. Find this number.
输入格式
The first line contains an integer n ( 1≤n≤105 ).
The second line contains n integers a1,a2,…,an ( 1≤ai≤n ).
输出格式
Output a single integer, indicating the maximal possible total number of segments.
输入输出样例
输入#1
7 1 1 2 2 3 3 3
输出#1
6
输入#2
7 1 2 3 4 5 6 7
输出#2
7
说明/提示
In the first example, we can choose a(0)=[1,2,3,3] , a(1)=[1,2,3] and seg(a(0))=seg(a(1))=3 . So the answer is 3+3=6 .
In the second example, we can choose a(0)=[1,2,3,4,5,6,7] and a(1) is empty. We can see that seg(a(0))=7 and seg(a(1))=0 . So the answer is 7+0=7 .