303184: CF620C. Pearls in a Row
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Pearls in a Row
题意翻译
现在有N个数,你的任务是将这N个数尽可能切割成多段。每一段必须包括两个相同的数。 数据输入量比较大,建议使用scanf和printf。 Input 单组测试数据。数据第一行为N(1 ≤ N ≤ 3·105) 。 数据的第二行包括N个数ai(1 ≤ ai ≤ 109) 。 Output 输出的第一行为尽可能切割的最大段数K。 接下来K行,每行为两个整数lj, rj (1 ≤ lj ≤ rj ≤ n) ,表示切割的区间范围 如果存在多个合法的切割方法,输出任意一个即可。 如果不能切割成合法的情况,输出"-1".题目描述
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 $ a_{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 $ n $ ( $ 1<=n<=3·10^{5} $ ) — the number of pearls in a row. The second line contains $ n $ integers $ a_{i} $ ( $ 1<=a_{i}<=10^{9} $ ) – the type of the $ i $ -th pearl.
输出格式
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 $ l_{j},r_{j} $ ( $ 1<=l_{j}<=r_{j}<=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".
输入输出样例
输入样例 #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