CF1082E.Increasing Frequency

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given array aa of length nn. You can choose one segment [l,r][l, r] (1≤l≤r≤n1 \le l \le r \le n) and integer value kk (positive, negative or even zero) and change al,al+1,…,ara_l, a_{l + 1}, \dots, a_r by kk each (i.e. ai:=ai+ka_i := a_i + k for each l≤i≤rl \le i \le r).

What is the maximum possible number of elements with value cc that can be obtained after one such operation?

给你一个长度为 nn 的数组 aa。你可以选择一个区间 [l,r][l, r](其中 1≤l≤r≤n1 \le l \le r \le n)和一个整数 kk(可以为正数、负数,甚至零),并将 al,al+1,…,ara_l, a_{l + 1}, \dots, a_r 中的每个元素都增加 kk(即对每个满足 l≤i≤rl \le i \le r 的 ii,执行 ai:=ai+ka_i := a_i + k)。

在执行一次这样的操作后,最多能得到多少个值为 cc 的元素?

输入格式

The first line contains two integers nn and cc (1≤n≤5⋅1051 \le n \le 5 \cdot 10^5, 1≤c≤5⋅1051 \le c \le 5 \cdot 10^5) — the length of array and the value cc to obtain.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤5⋅1051 \le a_i \le 5 \cdot 10^5) — array aa.

第一行包含两个整数 nn 和 cc(1≤n≤5⋅1051 \le n \le 5 \cdot 10^5,1≤c≤5⋅1051 \le c \le 5 \cdot 10^5)—— 分别表示数组的长度以及需要得到的值 cc。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤5⋅1051 \le a_i \le 5 \cdot 10^5)—— 数组 aa。

输出格式

Print one integer — the maximum possible number of elements with value cc which can be obtained after performing operation described above.

输出一个整数——执行上述操作后所能得到的值为 cc 的元素的最大可能数量。

输入输出样例

  • 输入#1

    6 9
    9 9 9 9 9 9

    输出#1

    6
  • 输入#2

    3 2
    6 2 6

    输出#2

    2

说明/提示

In the first example we can choose any segment and k=0k = 0. The array will stay same.

In the second example we can choose segment [1,3][1, 3] and k=−4k = -4. The array will become [2,−2,2][2, -2, 2].

在第一个例子中,我们可以选择任意区间,且 k=0k = 0。数组将保持不变。

在第二个例子中,我们可以选择区间 [1,3][1, 3],且 k=−4k = -4。数组将变为 [2,−2,2][2, -2, 2]。

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

首页