time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

There are n pearls in a row. Let’s enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.

Let’s call a sequence of consecutive pearls a segment. Let’s call a segment good if it contains two pearls of the same type.

Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.

As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

Input

The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row.

The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl.

Output

On the first line print integer k — the maximal number of segments in a partition of the row.

Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment.

Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type.

If there are several optimal solutions print any of them. You can print the segments in any order.

If there are no correct partitions of the row print the number “-1”.

Examples

input

5

1 2 3 4 1

output

1

1 5

input

5

1 2 3 4 5

output

-1

input

7

1 2 1 3 1 2 1

output

2

1 3

4 7

【题解】



给你长度为n的序列;

让你把这n个序列分割成最大数目的子段;

使得每个子段里面最少出现两个相同的数字;

用map来判重;

如果之前出现过一次当前扫描到的数字;

则把当前的头尾指针这段区间归为答案;

然后新的头尾指针指向下一个元素

不能直接输出答案,因为最后一段区间的右端点还要指向n;这样才能完成对整个区间的覆盖;

#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
#define lson L,m,rt<<1
#define rson m+1,R,rt<<1|1
#define LL long long using namespace std; const int MAXN = 4e5;
const int dx[5] = {0,1,-1,0,0};
const int dy[5] = {0,0,0,-1,1};
const double pi = acos(-1.0); int n;
map <int,int>dic;
vector < pair <int,int> > v; void input_LL(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)) t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} void input_int(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)) t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
bool find_ans = 0;
input_int(n);
int h = 1,t =1;
for (int i = 1;i <= n;i++)
{
int x;
input_int(x);
int temp = dic[x];
if (temp==0)
dic[x] = 1;
else
{
v.push_back(make_pair(h,t));
h = i+1,t = i;
dic.clear();
}
t++;
}
int len = v.size();
if (len == 0)
puts("-1");
else
{
printf("%d\n",len);
for (int i = 0;i <= len-2;i++)
printf("%d %d\n",v[i].first,v[i].second);
printf("%d %d\n",v[len-1].first,n);
}
return 0;
}

最新文章

  1. WPF+通过配置文件生成菜单(Menu)+源码
  2. HTML5--div、span超出部分省略号显示
  3. Java基础之I/O和file
  4. 登录到mysql查看binlog日志
  5. springmvc自定义日期编辑器
  6. jquery实践案例--验证电子邮箱
  7. a computer-centered view of information systems to a database-centered view
  8. android 数据持久化——I/O操作
  9. S3C2440的SPI解析
  10. Spring基础学习(二)&mdash;详解Bean(上)
  11. mybatis源码解读(二)——构建Configuration对象
  12. Linux时间子系统之(十五):clocksource
  13. Expression的烦恼
  14. source insight 添加 python 支持
  15. ref、out与params
  16. spring boot thymeleaf
  17. Spring Data Redis —— 快速入门
  18. 高能天气——团队Scrum冲刺阶段-Day 5
  19. NET MVC全局异常处理(一) 【转载】网站遭遇DDoS攻击怎么办 使用 HttpRequester 更方便的发起 HTTP 请求 C#文件流。 Url的Base64编码以及解码 C#计算字符串长度,汉字算两个字符 2019周笔记(2.18-2.23) Mysql语句中当前时间不能直接使用C#中的Date.Now传输 Mysql中Count函数的正确使用
  20. 【转】Tesla Model X的车门设计问题

热门文章

  1. 目标识别(object detection)中的 IoU(Intersection over Union)
  2. 主定理(Master Theorem)与时间复杂度
  3. ES6的学习之路(基础知识总结)
  4. oracle expdp 备份脚本
  5. echarts同一页面四个图表切换的js数据交互
  6. 【Educational Codeforces Round 31 B】Japanese Crosswords Strike Back
  7. 2019年Angular7——安装搭建路由
  8. Spark Streaming教程
  9. 安装spark1.3.1单机环境 分类: B8_SPARK 2015-04-27 14:52 1873人阅读 评论(0) 收藏
  10. 【BZOJ 4518】[Sdoi2016]征途