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;
typedef long long ll;
const ll MAXN=400010;
const ll inf=(1e18);
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, k, m, i, j;
cin>>n>>k>>m;
vector<ll> v(n+1, k+10);
vector<vector<ll>> dp(k+1, vector<ll> (n+1, 0));
for(ll i=1; i<=n; i++){
cin>>v[i];
}
for(i=1; i<=k; i++){
for(j=1; j<=n; j++){
if(i==v[j]){
dp[i][j]=dp[i][j-1]+1;
}
else {
dp[i][j]=dp[i][j-1];
}
}
}
while(m--){
ll test;
cin>>test;
if(test==1){
ll p, val;
cin>>p>>val;
for(i=p; i<=n; i++){
dp[v[p]][i]--;
}
v[p]=val;
for(i=p; i<=n; i++){
dp[v[p]][i]++;
}
}
else {
ll l=0, r=k, cavab=n+100;
while(r<=n){
bool f=true;
if(r-l<k){
r++;
continue;
}
for(ll i=1; i<=k; i++){
if(dp[i][r]-dp[i][l]==0){
f=false;
}
}
if(f){
cavab=min(cavab, r-l);
l++;
}
else {
r++;
}
}
if(cavab==n+100){
cout<<-1<<endl;
}
else {
cout<<cavab<<endl;
}
}
}
return 0;
}
# | 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... |