CF1394E.Boboniu and Banknote Collection
NOI/NOI+/CTSC
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
No matter what trouble you're in, don't be afraid, but face it with a smile.
I've made another billion dollars!
— Boboniu
Boboniu has issued his currencies, named Bobo Yuan. Bobo Yuan (BBY) is a series of currencies. Boboniu gives each of them a positive integer identifier, such as BBY-1, BBY-2, etc.
Boboniu has a BBY collection. His collection looks like a sequence. For example:

We can use sequence a=[1,2,3,3,2,1,4,4,1] of length n=9 to denote it.
Now Boboniu wants to fold his collection. You can imagine that Boboniu stick his collection to a long piece of paper and fold it between currencies:

Boboniu will only fold the same identifier of currencies together. In other words, if ai is folded over aj (1≤i,j≤n), then ai=aj must hold. Boboniu doesn't care if you follow this rule in the process of folding. But once it is finished, the rule should be obeyed.
A formal definition of fold is described in notes.
According to the picture above, you can fold a two times. In fact, you can fold a=[1,2,3,3,2,1,4,4,1] at most two times. So the maximum number of folds of it is 2.
As an international fan of Boboniu, you're asked to calculate the maximum number of folds.
You're given a sequence a of length n, for each i (1≤i≤n), you need to calculate the maximum number of folds of [a1,a2,…,ai].
无论你遇到什么困难,都不要害怕,而要微笑着面对它。
我又赚了十亿美元!
——Boboniu
Boboniu 发行了自己的货币,名为“波波元”(Bobo Yuan,简称 BBY)。波波元是一系列货币,Boboniu 为每种货币赋予一个正整数标识符,例如 BBY-1、BBY-2 等。
Boboniu 拥有一套波波元收藏。他的收藏可视为一个序列。例如:

我们可以用长度为 n=9 的序列 a=[1,2,3,3,2,1,4,4,1] 来表示它。
现在 Boboniu 想要折叠他的这套收藏。你可以想象:Boboniu 将这套收藏粘贴在一张长纸条上,然后在货币之间进行折叠:

Boboniu 只允许将相同标识符的货币叠在一起。换句话说,若 ai 被折叠到 aj 上(其中 1≤i,j≤n),则必须满足 ai=aj。Boboniu 并不关心你在折叠过程中是否始终遵守该规则;但一旦折叠完成,该规则必须被满足。
“折叠”的形式化定义见注释部分。
根据上图所示,序列 a 可以折叠两次。事实上,对于 a=[1,2,3,3,2,1,4,4,1],最多只能折叠两次,因此其最大折叠次数为 2。
作为 Boboniu 的国际粉丝,你需要计算最大折叠次数。
给定一个长度为 n 的序列 a,对每个 i(1≤i≤n),你需要计算前缀子序列 [a1,a2,…,ai] 的最大折叠次数。
输入格式
The first line contains an integer n (1≤n≤105).
The second line contains n integers a1,a2,…,an (1≤ai≤n).
第一行包含一个整数 n(1≤n≤105)。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n)。
输出格式
Print n integers. The i-th of them should be equal to the maximum number of folds of [a1,a2,…,ai].
输出 n 个整数。其中第 i 个整数应等于子数组 [a1,a2,…,ai] 的最大折叠次数。
输入输出样例
输入#1
9 1 2 3 3 2 1 4 4 1
输出#1
0 0 0 1 1 1 1 2 2
输入#2
9 1 2 2 2 2 1 1 2 2
输出#2
0 0 1 2 3 3 4 4 5
输入#3
15 1 2 3 4 5 5 4 3 2 2 3 4 4 3 6
输出#3
0 0 0 0 0 1 1 1 1 2 2 2 3 3 0
输入#4
50 1 2 4 6 6 4 2 1 3 5 5 3 1 2 4 4 2 1 3 3 1 2 2 1 1 1 2 4 6 6 4 2 1 3 5 5 3 1 2 4 4 2 1 3 3 1 2 2 1 1
输出#4
0 0 0 0 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 4 4 4 5 5 6 7 3 3 3 4 4 4 4 3 3 4 4 4 4 4 5 5 5 5 6 6 6 7 7 8
说明/提示
Formally, for a sequence a of length n, let's define the folding sequence as a sequence b of length n such that:
- bi (1≤i≤n) is either 1 or −1.
- Let p(i)=[bi=1]+∑j=1i−1bj. For all 1≤i<j≤n, if p(i)=p(j), then ai should be equal to aj.
([A] is the value of boolean expression A. i. e. [A]=1 if A is true, else [A]=0).
Now we define the number of folds of b as f(b)=∑i=1n−1[bi=bi+1].
The maximum number of folds of a is F(a)=maxf(b)∣b is a folding sequence of a.
形式化地,对于一个长度为 n 的序列 a,我们定义其折叠序列为一个长度为 n 的序列 b,满足以下条件:
- 对每个 i(1≤i≤n),bi 的值为 1 或 −1;
- 定义 p(i)=[bi=1]+∑j=1i−1bj。对任意 1≤i<j≤n,若 p(i)=p(j),则必须有 ai=aj。
(其中 [A] 表示布尔表达式 A 的取值:当 A 为真时 [A]=1,否则 [A]=0。)
现在我们定义序列 b 的折叠次数为 f(b)=∑i=1n−1[bi=bi+1]。
序列 a 的最大折叠次数定义为 F(a)=maxf(b)∣b 是 a 的一个折叠序列。
输入解题思路,AI测评打分。不知道怎么写?