A8741 | Array
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains two space-separated integers: $n$ and $k$ ( $1<=n,k<=10^{5}$ ). The second line contains $n$ space-separated integers $a_{1},a_{2},...,a_{n}$ — elements of the array $a$ ( $1<=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.
输入输出样例
输入 #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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted