CF1630C.Paint the Middle
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n elements numbered from 1 to n, the element i has value ai and color ci, initially, ci=0 for all i.
The following operation can be applied:
- Select three elements i, j and k (1≤i<j<k≤n), such that ci, cj and ck are all equal to 0 and ai=ak, then set cj=1.
Find the maximum value of i=1∑nci that can be obtained after applying the given operation any number of times.
给你 n 个编号为 1 到 n 的元素,其中第 i 个元素的值为 ai、颜色为 ci;初始时对所有 i 都有 ci=0。
可以执行如下操作:
- 选择三个元素 i、j 和 k(满足 1≤i<j<k≤n),使得 ci=cj=ck=0 且 ai=ak,然后将 cj 设为 1。
求经过任意次上述操作后,i=1∑nci 的最大可能值。
输入格式
The first line contains an integer n (3≤n≤2⋅105) — the number of elements.
The second line consists of n integers a1,a2,…,an (1≤ai≤n), where ai is the value of the i-th element.
第一行包含一个整数 n(3≤n≤2⋅105)—— 元素的个数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n),其中 ai 表示第 i 个元素的值。
输出格式
Print a single integer in a line — the maximum value of i=1∑nci that can be obtained after applying the given operation any number of times.
在一行中输出一个整数——在任意次数地执行给定操作后,所能得到的 i=1∑nci 的最大值。
输入输出样例
输入#1
7 1 2 1 2 7 4 7
输出#1
2
输入#2
13 1 2 3 2 1 3 3 4 5 5 5 4 7
输出#2
7
说明/提示
In the first test, it is possible to apply the following operations in order:

在第一次测试中,可以按以下顺序执行以下操作:

输入解题思路,AI测评打分。不知道怎么写?