//Dedicated to my love, ivaziva
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = int64_t;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define dbg(x) cerr<<#x<<": "<<x<<'\n';
#define dbga(A,l_,r_){for(int i_=l_;i_<=r_;i_++)cerr<<A[i_]<<' ';cerr<<'\n';}
#define dbgv(a_){for(auto x_:a_) cerr<<x_<<' ';cerr<<'\n';}
const int maxn = 2e5 + 3;
int n, k, r;
int a[maxn], info[maxn], f[maxn];
void Add(int x, int& cnt) {
f[x]++;
if (f[x] == info[x]) {
cnt++;
}
}
void Erase(int x, int& cnt) {
if (f[x] == info[x]) {
cnt--;
}
f[x]--;
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cout.tie(nullptr); cerr.tie(nullptr);
cin >> n >> k >> r;
for (int i = 0; i < maxn; i++) {
info[i] = -1;
}
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < r; i++) {
int B, Q;
cin >> B >> Q;
info[B] = Q;
}
int cnt = 0;
int R = -1;
int ans = maxn;
for (int i = 0; i < n; i++) {
while (R + 1 < n && cnt < r) {
R += 1;
Add(a[R], cnt);
}
if (cnt == r) {
ans = min(ans, R - i + 1);
}
Erase(a[i], cnt);
}
if (ans > n) {
cout << "impossible\n";
return 0;
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
0 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1084 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
0 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
1 ms |
1116 KB |
Output is correct |
4 |
Correct |
1 ms |
1248 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
1116 KB |
Output is correct |
7 |
Correct |
1 ms |
1116 KB |
Output is correct |
8 |
Correct |
0 ms |
1116 KB |
Output is correct |
9 |
Correct |
1 ms |
1116 KB |
Output is correct |
10 |
Correct |
0 ms |
1116 KB |
Output is correct |
11 |
Correct |
0 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1116 KB |
Output is correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
1228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
2396 KB |
Output is correct |
2 |
Correct |
15 ms |
2396 KB |
Output is correct |
3 |
Correct |
10 ms |
2648 KB |
Output is correct |
4 |
Correct |
9 ms |
2396 KB |
Output is correct |
5 |
Correct |
12 ms |
3488 KB |
Output is correct |
6 |
Correct |
8 ms |
2396 KB |
Output is correct |
7 |
Correct |
9 ms |
2392 KB |
Output is correct |
8 |
Correct |
14 ms |
3928 KB |
Output is correct |
9 |
Correct |
11 ms |
2908 KB |
Output is correct |
10 |
Correct |
9 ms |
2236 KB |
Output is correct |
11 |
Correct |
1 ms |
1116 KB |
Output is correct |
12 |
Correct |
1 ms |
1116 KB |
Output is correct |
13 |
Correct |
1 ms |
1116 KB |
Output is correct |
14 |
Correct |
1 ms |
1116 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1112 KB |
Output is correct |
17 |
Correct |
1 ms |
1116 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
0 ms |
1116 KB |
Output is correct |
20 |
Correct |
1 ms |
1116 KB |
Output is correct |
21 |
Correct |
1 ms |
1228 KB |
Output is correct |
22 |
Correct |
1 ms |
1112 KB |
Output is correct |
23 |
Correct |
1 ms |
1116 KB |
Output is correct |
24 |
Correct |
0 ms |
1116 KB |
Output is correct |
25 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
3928 KB |
Output is correct |
2 |
Correct |
18 ms |
3676 KB |
Output is correct |
3 |
Correct |
14 ms |
3328 KB |
Output is correct |
4 |
Correct |
8 ms |
2396 KB |
Output is correct |
5 |
Correct |
21 ms |
4320 KB |
Output is correct |
6 |
Correct |
26 ms |
4692 KB |
Output is correct |
7 |
Correct |
11 ms |
2908 KB |
Output is correct |
8 |
Correct |
14 ms |
3260 KB |
Output is correct |
9 |
Correct |
8 ms |
2396 KB |
Output is correct |
10 |
Correct |
9 ms |
2392 KB |
Output is correct |
11 |
Correct |
9 ms |
2396 KB |
Output is correct |
12 |
Correct |
9 ms |
2396 KB |
Output is correct |
13 |
Correct |
13 ms |
3268 KB |
Output is correct |
14 |
Correct |
8 ms |
2396 KB |
Output is correct |
15 |
Correct |
11 ms |
2596 KB |
Output is correct |
16 |
Correct |
14 ms |
3932 KB |
Output is correct |
17 |
Correct |
11 ms |
2808 KB |
Output is correct |
18 |
Correct |
8 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
1236 KB |
Output is correct |
20 |
Correct |
1 ms |
1116 KB |
Output is correct |
21 |
Correct |
1 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1212 KB |
Output is correct |
23 |
Correct |
1 ms |
1112 KB |
Output is correct |
24 |
Correct |
1 ms |
1112 KB |
Output is correct |
25 |
Correct |
1 ms |
1116 KB |
Output is correct |
26 |
Correct |
1 ms |
1116 KB |
Output is correct |
27 |
Correct |
1 ms |
1116 KB |
Output is correct |
28 |
Correct |
0 ms |
1116 KB |
Output is correct |
29 |
Correct |
1 ms |
1228 KB |
Output is correct |
30 |
Correct |
0 ms |
1116 KB |
Output is correct |
31 |
Correct |
1 ms |
1116 KB |
Output is correct |
32 |
Correct |
0 ms |
1116 KB |
Output is correct |
33 |
Correct |
1 ms |
1116 KB |
Output is correct |