#include<bits/stdc++.h>
using namespace std;
#define int long long
bool debug = false;
signed main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, k, r, temp; cin >> n >> k >> r;
bool found = false;
vector<int> v(n);
for (int i = 0 ;i < n; ++i){
cin >> v[i];
}
vector<int> val(k, 1e9+7);
for (int i = 0;i < r; ++i){
cin >> temp;
cin >> val[temp];
}
int lo = 0, hi = n+1, mid = (lo + hi)/2;
temp = 0;
while (lo < hi-1){
if(debug) cout << lo << ' ' << mid << ' ' << hi << " ";
temp = 0;
found = false;
vector<int> cur(n, 0);
for (int i = 0; i < mid; ++i){
cur[v[i]]++;
if(cur[v[i]] == val[v[i]])temp++;
}
if(debug)cout << temp << ' ';
if(temp == r){
hi = mid;
mid = (lo + hi)/2;
if(debug)cout <<'\n';
continue;
}
for (int i = mid; i < n && !found; ++i){
cur[v[i]]++;
cur[v[i-mid]]--;
if (v[i] != v[i-mid]){
if(cur[v[i]] == val[v[i]])temp++;
if (cur[v[i-mid]] == val[v[i-mid]]-1)temp--;
}
if(debug)cout << temp << ' ' ;
if(temp == r){
hi = mid;
mid = (lo + hi)/2;
if(debug)cout<<'\n';
found = true;
continue;
}
}
if(found)continue;
if(debug)cout<<'\n';
lo = mid;
mid = (lo + hi)/2;
}
if(debug)cout << temp << ' ';
if (temp != r && hi == n+1)cout << "impossible";
else cout << hi;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
0 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
3412 KB |
Output is correct |
2 |
Correct |
37 ms |
3432 KB |
Output is correct |
3 |
Correct |
18 ms |
3432 KB |
Output is correct |
4 |
Correct |
29 ms |
3436 KB |
Output is correct |
5 |
Correct |
49 ms |
4004 KB |
Output is correct |
6 |
Correct |
25 ms |
3412 KB |
Output is correct |
7 |
Correct |
27 ms |
3436 KB |
Output is correct |
8 |
Correct |
48 ms |
4976 KB |
Output is correct |
9 |
Correct |
30 ms |
3436 KB |
Output is correct |
10 |
Correct |
34 ms |
3412 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 |
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 |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
320 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
4056 KB |
Output is correct |
2 |
Correct |
47 ms |
3904 KB |
Output is correct |
3 |
Correct |
51 ms |
3920 KB |
Output is correct |
4 |
Correct |
11 ms |
3436 KB |
Output is correct |
5 |
Correct |
47 ms |
5916 KB |
Output is correct |
6 |
Correct |
63 ms |
6484 KB |
Output is correct |
7 |
Correct |
38 ms |
4424 KB |
Output is correct |
8 |
Correct |
59 ms |
4780 KB |
Output is correct |
9 |
Correct |
29 ms |
3796 KB |
Output is correct |
10 |
Correct |
36 ms |
3824 KB |
Output is correct |
11 |
Correct |
18 ms |
3888 KB |
Output is correct |
12 |
Correct |
26 ms |
3796 KB |
Output is correct |
13 |
Correct |
41 ms |
5204 KB |
Output is correct |
14 |
Correct |
23 ms |
3796 KB |
Output is correct |
15 |
Correct |
23 ms |
4000 KB |
Output is correct |
16 |
Correct |
47 ms |
6232 KB |
Output is correct |
17 |
Correct |
32 ms |
4440 KB |
Output is correct |
18 |
Correct |
34 ms |
3796 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 |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
372 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |