#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, ll>
const int MAX = 5005;
int n, m, k;
int arr[MAX];
int cnt[51];
bool check(int mid){
memset(cnt, 0, sizeof(cnt));
int zeros = k;
for (int i = 1; i <= mid; i++)
{
cnt[arr[i]]++;
if(cnt[arr[i]] == 1){
zeros --;
}
}
if(zeros == 0) return true;
for (int i = mid + 1; i <= n; i++)
{
cnt[arr[i]]++;
if(cnt[arr[i]] == 1){
zeros --;
}
cnt[arr[i - mid]]--;
if(cnt[arr[i - mid]] == 0){
zeros ++;
}
if(zeros == 0){
return true;
}
}
return false;
}
int search(){
int l = k, r = n;
int ans = -1;
while(l <= r){
int mid = (l + r) / 2;
if(check(mid)){
r = mid - 1;
ans = mid;
}
else{
l = mid + 1;
}
}
return ans;
}
int main(){
cin >> n >> k >> m;
for (int i = 1; i <= n; i++)
{
cin >> arr[i];
}
while(m--){
int t; cin >> t;
if(t == 1){
int i, a;
cin >> i >> a;
arr[i] = a;
}
else{
cout << search() << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
320 KB |
Output is correct |
2 |
Correct |
19 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
340 KB |
Output is correct |
2 |
Correct |
30 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
187 ms |
360 KB |
Output is correct |
2 |
Correct |
36 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |