CF1630C.Paint the Middle

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given nn elements numbered from 11 to nn, the element ii has value aia_i and color cic_i, initially, ci=0c_i = 0 for all ii.

The following operation can be applied:

  • Select three elements ii, jj and kk (1≤i<j<k≤n1 \leq i \lt j \lt k \leq n), such that cic_i, cjc_j and ckc_k are all equal to 00 and ai=aka_i = a_k, then set cj=1c_j = 1.

Find the maximum value of ∑i=1nci\sum\limits_{i=1}^n{c_i} that can be obtained after applying the given operation any number of times.

给你 nn 个编号为 11 到 nn 的元素,其中第 ii 个元素的值为 aia_i、颜色为 cic_i;初始时对所有 ii 都有 ci=0c_i = 0。

可以执行如下操作:

  • 选择三个元素 ii、jj 和 kk(满足 1≤i<j<k≤n1 \leq i \lt j \lt k \leq n),使得 ci=cj=ck=0c_i = c_j = c_k = 0 且 ai=aka_i = a_k,然后将 cjc_j 设为 11。

求经过任意次上述操作后,∑i=1nci\sum\limits_{i=1}^n{c_i} 的最大可能值。

输入格式

The first line contains an integer nn (3≤n≤2⋅1053 \leq n \leq 2 \cdot 10^5) — the number of elements.

The second line consists of nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤n1 \leq a_i \leq n), where aia_i is the value of the ii-th element.

第一行包含一个整数 nn(3≤n≤2⋅1053 \leq n \leq 2 \cdot 10^5)—— 元素的个数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤n1 \leq a_i \leq n),其中 aia_i 表示第 ii 个元素的值。

输出格式

Print a single integer in a line — the maximum value of ∑i=1nci\sum\limits_{i=1}^n{c_i} that can be obtained after applying the given operation any number of times.

在一行中输出一个整数——在任意次数地执行给定操作后,所能得到的 ∑i=1nci\sum\limits_{i=1}^n{c_i} 的最大值。

输入输出样例

  • 输入#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测评打分。不知道怎么写?

首页