CF620C.Pearls in a Row

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

There are nn pearls in a row. Let's enumerate them with integers from 11 to nn from the left to the right. The pearl number ii has the type aia_{i} .

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.

输入格式

The first line contains integer nn ( 1<=n<=31051<=n<=3·10^{5} ) — the number of pearls in a row.

The second line contains nn integers aia_{i} ( 1<=ai<=1091<=a_{i}<=10^{9} ) – the type of the ii -th pearl.

输出格式

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

Each of the next kk lines should contain two integers lj,rjl_{j},r_{j} ( 1<=lj<=rj<=n1<=l_{j}<=r_{j}<=n ) — the number of the leftmost and the rightmost pearls in the jj -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".

输入输出样例

  • 输入#1

    5
    1 2 3 4 1
    

    输出#1

    1
    1 5
    
  • 输入#2

    5
    1 2 3 4 5
    

    输出#2

    -1
    
  • 输入#3

    7
    1 2 1 3 1 2 1
    

    输出#3

    2
    1 3
    4 7
    
首页