#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myrand(ll B){
return (ull)rng() % B;
}
inline double time() {
return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n,k,q; cin >> n >> k >> q;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> b(k);
for (int i = 0; i < q; ++i) {
int x,y; cin >> x >> y;
b[x] = y;
}
vector<int> c(k);
int cnt = 0;
for (int i = 0; i < k; ++i) {
if(c[i] >= b[i]) cnt++;
}
int res = n+1;
int r = 0;
for (int l = 0; l < n; ++l) {
while(r < n and cnt < k){
c[a[r]]++;
if(c[a[r]] == b[a[r]]) cnt++;
r++;
}
if(cnt == k){
res = min(res, r-l);
}
if(c[a[l]] == b[a[l]]) cnt--;
c[a[l]]--;
}
if(res == n+1){
cout << "impossible" << endl;
}
else{
cout << res << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
280 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
340 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1488 KB |
Output is correct |
2 |
Correct |
11 ms |
1488 KB |
Output is correct |
3 |
Correct |
13 ms |
1484 KB |
Output is correct |
4 |
Correct |
11 ms |
1488 KB |
Output is correct |
5 |
Correct |
17 ms |
2760 KB |
Output is correct |
6 |
Correct |
12 ms |
1492 KB |
Output is correct |
7 |
Correct |
15 ms |
1620 KB |
Output is correct |
8 |
Correct |
18 ms |
3912 KB |
Output is correct |
9 |
Correct |
15 ms |
2072 KB |
Output is correct |
10 |
Correct |
12 ms |
1492 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
356 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
3404 KB |
Output is correct |
2 |
Correct |
23 ms |
3140 KB |
Output is correct |
3 |
Correct |
19 ms |
2892 KB |
Output is correct |
4 |
Correct |
11 ms |
1492 KB |
Output is correct |
5 |
Correct |
30 ms |
4036 KB |
Output is correct |
6 |
Correct |
31 ms |
4492 KB |
Output is correct |
7 |
Correct |
17 ms |
2124 KB |
Output is correct |
8 |
Correct |
18 ms |
2508 KB |
Output is correct |
9 |
Correct |
11 ms |
1488 KB |
Output is correct |
10 |
Correct |
11 ms |
1492 KB |
Output is correct |
11 |
Correct |
12 ms |
1548 KB |
Output is correct |
12 |
Correct |
12 ms |
1532 KB |
Output is correct |
13 |
Correct |
16 ms |
2760 KB |
Output is correct |
14 |
Correct |
11 ms |
1492 KB |
Output is correct |
15 |
Correct |
12 ms |
1620 KB |
Output is correct |
16 |
Correct |
20 ms |
3912 KB |
Output is correct |
17 |
Correct |
15 ms |
2112 KB |
Output is correct |
18 |
Correct |
12 ms |
1488 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
336 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 |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
324 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
324 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |