/*
~2021~
*/
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
#define pii pair<int,int>
#define debug(x) cout << #x << '=' << x << endl;
const int N = 2e5 + 5;
const int INF = 1e9;
const ll mod = 1e9+7;
int need[N],arr[N],n,k,q,byk[N];
bool valid(int x){
for(int i = 0;i<k;i++) byk[i] = 0;
int cnt = 0;
for(int i = 1;i<=n;i++){
if(i > x){
if(byk[arr[i-x]] == need[arr[i-x]]) cnt--;
byk[arr[i-x]]--;
}
byk[arr[i]]++;
if(byk[arr[i]] == need[arr[i]]) cnt++;
if(cnt == q) return true;
}
return false;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(,r,stdin);
//freopen(,w,stdout);
cin>>n>>k>>q;
for(int i = 1;i<=n;i++) cin>>arr[i];
for(int i = 1;i<=q;i++){
int x,y;
cin>>x>>y;
need[x] = y;
}
int ki = 1,ka = n;
int pos = -1;
while(ki <= ka){
int mid = (ki + ka)/2;
if(valid(mid)){
pos = mid;
ka = mid-1;
}
else{
ki = mid + 1;
}
}
if(pos == -1) cout<<"impossible"<<endl;
else cout<<pos<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
1484 KB |
Output is correct |
2 |
Correct |
36 ms |
1480 KB |
Output is correct |
3 |
Correct |
20 ms |
1484 KB |
Output is correct |
4 |
Correct |
28 ms |
1520 KB |
Output is correct |
5 |
Correct |
39 ms |
2532 KB |
Output is correct |
6 |
Correct |
27 ms |
1500 KB |
Output is correct |
7 |
Correct |
28 ms |
1592 KB |
Output is correct |
8 |
Correct |
46 ms |
3140 KB |
Output is correct |
9 |
Correct |
33 ms |
2108 KB |
Output is correct |
10 |
Correct |
36 ms |
1484 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
324 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
3400 KB |
Output is correct |
2 |
Correct |
53 ms |
3084 KB |
Output is correct |
3 |
Correct |
58 ms |
2848 KB |
Output is correct |
4 |
Correct |
15 ms |
1484 KB |
Output is correct |
5 |
Correct |
57 ms |
4040 KB |
Output is correct |
6 |
Correct |
72 ms |
4476 KB |
Output is correct |
7 |
Correct |
36 ms |
2120 KB |
Output is correct |
8 |
Correct |
49 ms |
2344 KB |
Output is correct |
9 |
Correct |
33 ms |
1392 KB |
Output is correct |
10 |
Correct |
32 ms |
1488 KB |
Output is correct |
11 |
Correct |
20 ms |
1484 KB |
Output is correct |
12 |
Correct |
28 ms |
1496 KB |
Output is correct |
13 |
Correct |
46 ms |
2564 KB |
Output is correct |
14 |
Correct |
27 ms |
1480 KB |
Output is correct |
15 |
Correct |
30 ms |
1588 KB |
Output is correct |
16 |
Correct |
47 ms |
3156 KB |
Output is correct |
17 |
Correct |
35 ms |
2104 KB |
Output is correct |
18 |
Correct |
34 ms |
1480 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |