224B.md (2000B)
1 Source: https://codeforces.com/problemset/problem/224/B 2 3 B. Array 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 You've got an array *a*, consisting of *n* integers: *a*1, *a*2, ..., *a**n*. Your task is to find a minimal by inclusion segment [*l*, *r*] (1 ≤ *l* ≤ *r* ≤ *n*) such, that among numbers *a**l*, *a**l* + 1, ..., *a**r* there are exactly *k* distinct numbers. 22 23 Segment [*l*, *r*] (1 ≤ *l* ≤ *r* ≤ *n*; *l*, *r* are integers) of length *m* = *r* - *l* + 1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*, *y*] satisfying the property and less then *m* in length, such that 1 ≤ *l* ≤ *x* ≤ *y* ≤ *r* ≤ *n*. Note that the segment [*l*, *r*] doesn't have to be minimal in length among all segments, satisfying the given property. 24 25 Input 26 27 The first line contains two space-separated integers: *n* and *k* (1 ≤ *n*, *k* ≤ 105). The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* — elements of the array *a* (1 ≤ *a**i* ≤ 105). 28 29 Output 30 31 Print a space-separated pair of integers *l* and *r* (1 ≤ *l* ≤ *r* ≤ *n*) such, that the segment [*l*, *r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. 32 33 Examples 34 35 Input 36 37 ``` 38 4 2 39 1 2 2 3 40 ``` 41 42 Output 43 44 ``` 45 1 2 46 ``` 47 48 Input 49 50 ``` 51 8 3 52 1 1 2 2 3 3 4 5 53 ``` 54 55 Output 56 57 ``` 58 2 5 59 ``` 60 61 Input 62 63 ``` 64 7 4 65 4 7 7 4 7 4 7 66 ``` 67 68 Output 69 70 ``` 71 -1 -1 72 ``` 73 74 Note 75 76 In the first sample among numbers *a*1 and *a*2 there are exactly two distinct numbers. 77 78 In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments. 79 80 In the third sample there is no segment with four distinct numbers.