This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |