-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path13.cpp
44 lines (32 loc) · 823 Bytes
/
13.cpp
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
41
42
43
44
// O(n)
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
#define FILE_IO {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL)
int main() {
FAST_IO;
// FILE_IO;
int n, k, a[100010], f[100010] = {0}, dst = 0;
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int j = 0, i = 0; i < n; ++i) {
dst += (f[a[i]] == 0);
f[a[i]] += 1;
while (dst >= k) {
f[a[j]] -= 1;
dst -= (f[a[j]] == 0);
if (dst < k) {
cout << j + 1 << " " << i + 1;
return 0;
}
j += 1;
}
}
cout << "-1 -1";
return 0;
}