#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define ii pair<int,int>
#define BIT(mask,x) (((mask)>>(x))&(1))
#define MASK(x) ((LL)(1)<<(x))
#define FOR(i,a,b) for(int i = (a),_b=(b); i<=_b;++i)
#define FORD(i,a,b) for(int i =(a),_b=(b);i>=_b;--i)
template<class X,class Y>
bool maximize(X &x,Y y){
if (x<y) return x=y,true; else return false;
}
template<class X,class Y>
bool minimize(X &x,Y y){
if (x>y) return x=y,true; else return false;
}
template<class T>
void compress(vector<T>&data){
sort(data.begin() , data.end());
data.resize(unique(data.begin() , data.end()) - data.begin());
}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
LL Rand(LL l,LL r){
return uniform_int_distribution<LL>(l,r)(rng);
}
const int N = (int) 1e5;
const int MAXK = (int)50;
const int inf = 1e9;
int a[N+2] ;
int n , m , k;
class IT{
public:
vector<int>st;
void load_size(int _n){
st = vector<int>(_n*4+2,0);
return;
}
#define lef(id) id*2
#define rig(id) id*2+1
void upd(int id,int l,int r,int pos,int val){
if (l==r) st[id] = val;
else {
int m = (l+r)/2;
if (pos <= m) upd(lef(id) , l , m , pos , val);
else upd(rig(id) , m + 1 , r , pos , val);
st[id] = max(st[id*2],st[id*2+1]);
}
}
int Get(int id,int l,int r,int need_l,int need_r){
if (l > need_r || r < need_l) return -inf;
if (need_l <= l && r <= need_r) return st[id];
int m = (l+r)/2;
return max(Get(lef(id),l,m,need_l,need_r) , Get(rig(id),m+1,r,need_l,need_r));
}
};
IT res;
IT tmp;
set<int>pos[MAXK+2];
int ans[N+2] = {};
int Get_ans(){
int ss = 0;
int cnt[MAXK+2] = {};
for(int i = 1 , j = 1; i <= n; ++i){
while (j <= n && ss != k) {
if (cnt[a[j]]==0) ++ss;
cnt[a[j]]++;
++j;
}
if (ss != k) ans[i] = inf; else ans[i] = j - i;
--cnt[a[i]];
if (cnt[a[i]]==0) --ss;
}
int x = *min_element(ans+1,ans+n+1);
if (x==inf) return -1; else return x;
}
void process(int need_p,int val){
a[need_p] = val;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0) ; cout.tie(0) ;
#define name "main"
if (fopen(name".inp","r")){
freopen(name".inp","r",stdin);
freopen(name".ans","w",stdout);
}
cin >> n >> k >> m;
FOR(i,1,n) cin >> a[i];
while(m--){
int t; cin>>t;
if (t==2) cout<<Get_ans()<<'\n';
else {
int p,val; cin>>p>>val;
process(p,val);
}
}
return 0;
}
Compilation message (stderr)
nekameleoni.cpp: In function 'int main()':
nekameleoni.cpp:91:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
nekameleoni.cpp:92:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | freopen(name".ans","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |