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;
}

【32.26%】【codeforces 620C】Pearls in a Row的更多相关文章

  1. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  2. 【26.83%】【Codeforces Round #380C】Road to Cinema

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. 【32.22%】【codeforces 602B】Approximating a Constant Range

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【32.89%】【codeforces 574D】Bear and Blocks

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【26.09%】【codeforces 579C】A Problem about Polyline

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【26.67%】【codeforces 596C】Wilbur and Points

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【23.26%】【codeforces 747D】Winter Is Coming

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【codeforces 797C】Minimal string

    [题目链接]:http://codeforces.com/contest/797/problem/C [题意] 一开始,给你一个字符串s:两个空字符串t和u; 你有两种合法操作; 1.将s的开头字符加 ...

  9. 【codeforces 510C】Fox And Names

    [题目链接]:http://codeforces.com/contest/510/problem/C [题意] 给你n个字符串; 问你要怎么修改字典序; (即原本是a,b,c..z现在你可以修改每个字 ...

随机推荐

  1. Oracle批量插入在C#中的应用

    public void SetUserReportResult(int[] reportId, bool isReceive, string result) { if (reportId == nul ...

  2. [RxJS] Stopping a shared observable execution

    ConnectableObservable has the connect() method to conveniently dictate the start of the shared execu ...

  3. 【u248】交通序列号

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 在一条笔直的道路上共有N个路口,每个路口处都有关于该条道路的通行的信号灯. 显然,信号灯共有绿(G). ...

  4. UILabel调整字间距

    1.引入 在文件导入 #import <CoreText/CoreText.h> 2.程序 NSMutableAttributedString *attributedString =[[N ...

  5. [Angular2 Form] Validation message for Reactive form

    <div class="form-field"> <label>Confirm Password: </label> <input typ ...

  6. h5 video 点击自动全屏

    加上如下属性 https://blog.csdn.net/weixin_40974504/article/details/79639478 可阻止自动全屏播放,感谢 https://blog.csdn ...

  7. pppoe-环境下的mtu和mss

    路由器上在宽带拨号高级设置页面会有设置数据包MTU的页面 数据包MTU(字节):1480 (默认是1480,如非必要,请勿修改) PPPoE/ADSL:1492 ,可以尝试修改为1492 MTU: M ...

  8. JVM调优2

    原文地址:https://blog.csdn.net/sun1021873926/article/details/78002118 一.什么是JVM  JVM是Java Virtual Machine ...

  9. 【32.22%】【codeforces 602B】Approximating a Constant Range

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  10. IntelliJ IDEA设置鼠标悬浮提示

    测试代码; public interface MyInterface { /** * 我是接口方法的注释 * @param num1 我是接口方法入参的注释 * @return 我是接口方法返回值的注 ...