#include <iostream>
using namespace std;
const int N = 2e5;
namespace ds {
int c[N], g[N], z;
void add(int x) {
if (g[x] > 0) z -= ++c[x] == g[x];
}
void rem(int x) {
if (g[x] > 0) z += c[x]-- == g[x];
}
} // namespace ds
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, k, m;
cin >> n >> k >> m;
static int a[N];
for (int i = 0; i < n; i++) cin >> a[i];
for (int h = 0; h < m; h++) {
int i;
cin >> i;
cin >> ds::g[i];
}
ds::z = m;
int x = n + 1;
for (int i = 0, j = 0; i < n; i++) {
while (j < n && ds::z > 0) ds::add(a[j++]);
if (ds::z == 0) x = min(x, j - i);
ds::rem(a[i]);
}
if (x == n + 1)
cout << "impossible\n";
else
cout << x << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1424 KB |
Output is correct |
2 |
Correct |
10 ms |
1492 KB |
Output is correct |
3 |
Correct |
10 ms |
1544 KB |
Output is correct |
4 |
Correct |
12 ms |
1456 KB |
Output is correct |
5 |
Correct |
13 ms |
2280 KB |
Output is correct |
6 |
Correct |
9 ms |
1452 KB |
Output is correct |
7 |
Correct |
10 ms |
1616 KB |
Output is correct |
8 |
Correct |
14 ms |
2388 KB |
Output is correct |
9 |
Correct |
12 ms |
1988 KB |
Output is correct |
10 |
Correct |
11 ms |
1488 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
324 KB |
Output is correct |
23 |
Correct |
1 ms |
328 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
3380 KB |
Output is correct |
2 |
Correct |
19 ms |
3164 KB |
Output is correct |
3 |
Correct |
16 ms |
2772 KB |
Output is correct |
4 |
Correct |
10 ms |
1508 KB |
Output is correct |
5 |
Correct |
28 ms |
4044 KB |
Output is correct |
6 |
Correct |
25 ms |
4488 KB |
Output is correct |
7 |
Correct |
12 ms |
2072 KB |
Output is correct |
8 |
Correct |
16 ms |
2424 KB |
Output is correct |
9 |
Correct |
9 ms |
1520 KB |
Output is correct |
10 |
Correct |
10 ms |
1492 KB |
Output is correct |
11 |
Correct |
10 ms |
1460 KB |
Output is correct |
12 |
Correct |
9 ms |
1492 KB |
Output is correct |
13 |
Correct |
12 ms |
2232 KB |
Output is correct |
14 |
Correct |
9 ms |
1492 KB |
Output is correct |
15 |
Correct |
10 ms |
1692 KB |
Output is correct |
16 |
Correct |
14 ms |
2388 KB |
Output is correct |
17 |
Correct |
11 ms |
2004 KB |
Output is correct |
18 |
Correct |
9 ms |
1416 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |