CF250C.Movie Critics

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A film festival is coming up in the city N. The festival will last for exactly n days and each day will have a premiere of exactly one film. Each film has a genre — an integer from 1 to k.

On the i-th day the festival will show a movie of genre a__i. We know that a movie of each of k genres occurs in the festival programme at least once. In other words, each integer from 1 to k occurs in the sequence _a_1, _a_2, ..., a__n at least once.

Valentine is a movie critic. He wants to watch some movies of the festival and then describe his impressions on his site.

As any creative person, Valentine is very susceptive. After he watched the movie of a certain genre, Valentine forms the mood he preserves until he watches the next movie. If the genre of the next movie is the same, it does not change Valentine's mood. If the genres are different, Valentine's mood changes according to the new genre and Valentine has a stress.

Valentine can't watch all n movies, so he decided to exclude from his to-watch list movies of one of the genres. In other words, Valentine is going to choose exactly one of the k genres and will skip all the movies of this genre. He is sure to visit other movies.

Valentine wants to choose such genre x (1 ≤ x ≤ k), that the total number of after-movie stresses (after all movies of genre x are excluded) were minimum.

一场电影节即将在城市 N 举办。电影节持续恰好 nn 天,每天将上映一部电影的首映式。每部电影都有一个类型——一个从 11 到 kk 的整数。

第 ii 天放映的电影类型为 aia_i。已知电影节节目单中包含全部 kk 种类型的电影,至少各一次。换言之,整数 11 到 kk 中的每一个都在序列 a1, a2, ..., ana_1,\,a_2,\,...,\,a_n 中至少出现一次。

瓦伦丁是一名影评人。他打算观看电影节中的若干部电影,然后在自己的网站上撰写观影感受。

作为一名富有创造力的人,瓦伦丁的情绪非常敏感。每当他看完某一部类型电影后,便会形成一种情绪,并一直保持该情绪,直到他观看下一部电影为止。若下一部电影类型相同,则他的情绪不会改变;若类型不同,则他的情绪会依据新电影的类型而改变,此时瓦伦丁会产生一次“观影压力”(stress)。

瓦伦丁无法观看全部 nn 部电影,因此他决定从自己的观影清单中排除某一类电影。换句话说,瓦伦丁将从 kk 种类型中恰好选择一种类型 xx,并跳过所有类型为 xx 的电影;其余电影他都会观看。

瓦伦丁希望选择一个类型 xx(其中 1≤x≤k1 \le x \le k),使得在剔除所有类型为 xx 的电影后,剩余观影序列所产生的总观影压力次数最小。

输入格式

The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 105), where n is the number of movies and k is the number of genres.

The second line of the input contains a sequence of n positive integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ k), where a__i is the genre of the i-th movie. It is guaranteed that each number from 1 to k occurs at least once in this sequence.

输入的第一行包含两个整数 nn 和 kk(2 ≤ k ≤ n ≤ 1052 \le k \le n \le 10^5),其中 nn 表示电影的数量,kk 表示类型的数量。

输入的第二行包含一个由 nn 个正整数 a1,a2,…,ana_1, a_2, \dots, a_n(1 ≤ ai ≤ k1 \le a_i \le k)组成的序列,其中 aia_i 表示第 ii 部电影的类型。保证从 11 到 kk 的每个整数在该序列中至少出现一次。

输出格式

Print a single number — the number of the genre (from 1 to k) of the excluded films. If there are multiple answers, print the genre with the minimum number.

输出一个数字——被排除的电影所属的类型编号(从 1 到 kk)。如果存在多个答案,输出编号最小的类型。

输入输出样例

  • 输入#1

    10 3
    1 1 2 3 2 3 3 1 1 3

    输出#1

    3
  • 输入#2

    7 3
    3 1 3 2 3 1 2

    输出#2

    1

说明/提示

In the first sample if we exclude the movies of the 1st genre, the genres 2, 3, 2, 3, 3, 3 remain, that is 3 stresses; if we exclude the movies of the 2nd genre, the genres 1, 1, 3, 3, 3, 1, 1, 3 remain, that is 3 stresses; if we exclude the movies of the 3rd genre the genres 1, 1, 2, 2, 1, 1 remain, that is 2 stresses.

In the second sample whatever genre Valentine excludes, he will have exactly 3 stresses.

在第一个样例中,如果我们排除第 1 类电影,则剩余的类型为 2, 3, 2, 3, 3, 3,即有 3 个“重音”;如果我们排除第 2 类电影,则剩余的类型为 1, 1, 3, 3, 3, 1, 1, 3,即有 3 个“重音”;如果我们排除第 3 类电影,则剩余的类型为 1, 1, 2, 2, 1, 1,即有 2 个“重音”。

在第二个样例中,无论瓦伦丁排除哪一类电影,他都将恰好剩下 3 个“重音”。

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

首页