This repository was archived by the owner on Sep 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1091.cpp
More file actions
97 lines (88 loc) · 1.9 KB
/
1091.cpp
File metadata and controls
97 lines (88 loc) · 1.9 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
auto nextInt () -> int;
auto readN (int *array, int n) -> void;
template <typename T>
auto print (const T &) -> void;
template <typename T>
auto println (const T &) -> void;
template <typename T>
auto printsp (const T &) -> void;
const int kMaxn = 1e6 + 10;
const int kMaxm = 2e3 + 10;
int count[kMaxm];
int a[kMaxn];
auto main () -> int {
int n = nextInt(), m = nextInt();
int l = 0, r = -1;
readN(a, n);
int min = kMaxn + 1, minAt = 0;
while (r < n) {
for (int i = 0; i < m; ++i) {
while (count[i] == 0) {
++r;
if (r >= n) goto final;
++count[a[r] - 1];
}
}
while (true) {
if (min > r - l + 1) {
min = r - l + 1;
minAt = l;
}
if (--count[a[l++] - 1] == 0) break;
}
}
final:
printsp(minAt + 1);
printsp(min + minAt);
return 0;
}
auto nextInt () -> int {
int i = 0, sign = 1;
char c;
while (!isdigit(c = getchar())) if (c == '-') sign = -1;
do {
i = i * 10 + c - '0';
} while (isdigit(c = getchar()));
return i * sign;
}
auto readN (int *array, int n) -> void {
for (int i = 0; i < n; ++i) array[i] = nextInt();
}
template <>
auto print<int> (const int &val) -> void {
printf("%d", val);
}
template <>
auto print<char> (const char &val) -> void {
putchar(val);
}
template <>
auto print<char *> (char * const &val) -> void {
printf("%s", val);
}
template <>
auto print<const char *> (const char * const &val) -> void {
printf("%s", val);
}
template <>
auto print<long long> (const long long &val) -> void {
printf("%lld", val);
}
template <>
auto print<unsigned long long> (const unsigned long long &val) -> void {
printf("%llu", val);
}
template <typename T>
auto println (const T &val) -> void {
print(val);
putchar('\n');
}
template <typename T>
auto printsp (const T &val) -> void {
print(val);
putchar(' ');
}