#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, ll>
const int MAX = 100005;
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 |
33 ms |
212 KB |
Output is correct |
2 |
Correct |
16 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
156 ms |
212 KB |
Output is correct |
2 |
Correct |
25 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
180 ms |
312 KB |
Output is correct |
2 |
Correct |
35 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3072 ms |
640 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3041 ms |
764 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3064 ms |
724 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3050 ms |
808 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3060 ms |
784 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3068 ms |
980 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3076 ms |
1040 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |