-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask620C.java
More file actions
40 lines (39 loc) · 1.2 KB
/
Task620C.java
File metadata and controls
40 lines (39 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.*;
import java.io.*;
public class Task620C {
public static void main(String[] args) throws Exception {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.valueOf(r.readLine());
String[] str = r.readLine().split(" ");
int num = 0;
Set<String> seen = new HashSet<>();
Stack<Tuple> segments = new Stack<>();
int s = 0;
for(int i = 0; i < str.length; i++) {
if(seen.contains(str[i])) {
num++;
seen = new HashSet<>();
segments.push(new Tuple(s + 1, i + 1));
s = i + 1;
} else {
seen.add(str[i]);
}
}
if(!segments.isEmpty() && segments.peek().b != str.length) {
segments.peek().b = str.length;
}
PrintWriter pw = new PrintWriter(System.out);
pw.println(num == 0 ? "-1" : num);
for(Tuple t: segments) {
pw.println(t.a + " " + t.b);
}
pw.flush();
}
static class Tuple {
Integer a, b;
public Tuple(Integer a, Integer b) {
this.a = a;
this.b = b;
}
}
}