CF224B.Array

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You've got an array a, consisting of n integers: _a_1, _a_2, ..., a__n. Your task is to find a minimal by inclusion segment [l, r] (1 ≤ l ≤ r ≤ n) such, that among numbers a__l,  a__l + 1,  ...,  a__r there are exactly k distinct numbers.

Segment [l, r] (1 ≤ l ≤ r ≤ n; l, r are integers) of length m = r - l + 1, satisfying the given property, is called minimal by inclusion, if there is no segment [x, y] satisfying the property and less then m in length, such that 1 ≤ l ≤ x ≤ y ≤ r ≤ n. Note that the segment [l, r] doesn't have to be minimal in length among all segments, satisfying the given property.

你有一个包含 nn 个整数的数组 aa:a1, a2, …, ana_1,\,a_2,\,\dots,\,a_n。你的任务是找出一个按包含关系极小的区间 [l, r][l,\,r](其中 1≤l≤r≤n1\leq l \leq r \leq n),使得在数 al, al+1, …, ara_l,\,a_{l+1},\,\dots,\,a_r 中恰好有 kk 个互不相同的数。

长度为 m=r−l+1m = r - l + 1 的区间 [l, r][l,\,r](其中 1≤l≤r≤n1 \leq l \leq r \leq n,且 l, rl,\,r 为整数),若满足上述性质,则称其为按包含关系极小的,当且仅当不存在满足该性质、长度小于 mm 的区间 [x, y][x,\,y],使得 1≤l≤x≤y≤r≤n1 \leq l \leq x \leq y \leq r \leq n。注意:区间 [l, r][l,\,r] 并不要求是在所有满足该性质的区间中长度最短的。

输入格式

The first line contains two space-separated integers: n and k (1 ≤ n, k ≤ 105). The second line contains n space-separated integers _a_1, _a_2, ..., a__n — elements of the array a (1 ≤ a__i ≤ 105).

第一行包含两个用空格分隔的整数:nn 和 kk(1 ≤ n, k ≤ 1051 ≤ n, k ≤ 10^5)。第二行包含 nn 个用空格分隔的整数 a1, a2, ..., ana_1, a_2, ..., a_n —— 数组 aa 的元素(1 ≤ ai ≤ 1051 ≤ a_i ≤ 10^5)。

输出格式

Print a space-separated pair of integers l and r (1 ≤ l ≤ r ≤ n) such, that the segment [l, r] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them.

输出一对以空格分隔的整数 ll 和 rr(满足 1 ≤ l ≤ r ≤ n1 ≤ l ≤ r ≤ n),使得区间 [l, r][l, r] 是该问题的答案。如果所求区间不存在,则输出 -1 -1(不带引号)。如果有多个正确答案,输出任意一个即可。

输入输出样例

  • 输入#1

    4 2
    1 2 2 3

    输出#1

    1 2
  • 输入#2

    8 3
    1 1 2 2 3 3 4 5

    输出#2

    2 5
  • 输入#3

    7 4
    4 7 7 4 7 4 7

    输出#3

    -1 -1

说明/提示

In the first sample among numbers _a_1 and _a_2 there are exactly two distinct numbers.

In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.

In the third sample there is no segment with four distinct numbers.

在第一个样例中,在数字 a1a_1 和 a2a_2 中恰好有两个不同的数。

在第二个样例中,区间 [2, 5][2,\,5] 是包含三个不同数字的极小(按包含关系)区间,但它并非所有此类区间中长度最短的。

在第三个样例中,不存在包含四个不同数字的区间。

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

首页