This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// KALAM
# include<bits/stdc++.h>
# define lc (id << 1)
# define rc (lc ^ 1)
# define md ((l + r) >> 1)
using namespace std;
const int N = 100000 + 77 , K = 52;
int n , k , q , a[N] , P[K];
int L[N << 2][K] , R[N << 2][K] , dp[N << 2];
inline void Merge(int id) {
for(int i = 1;i <= k;++ i)
L[id][i] = min(L[lc][i] , L[rc][i]) , R[id][i] = max(R[lc][i] , R[rc][i]);
dp[id] = min(dp[lc] , dp[rc]);
for(int i = 1;i <= k;++ i)
if(L[id][i] < 1 || L[id][i] > n)
return ;
sort(P + 1 , P + 1 + k , [&](int x , int y) { return R[lc][x] < R[lc][y];} );
int nowr = -N;
for(int i = 1;i < k;++ i) {
nowr = max(nowr , L[rc][P[i]]);
if(L[rc][P[i]] < 1 || L[rc][P[i]] > n)
break ;
if(R[lc][P[i + 1]] > n || R[lc][P[i + 1]] < 1)
continue ;
dp[id] = min(dp[id] , nowr - R[lc][P[i + 1]] + 1);
}
}
void Update(int x , int l = 1 , int r = n + 1 , int id = 1) {
dp[id] = N;
if(r - l < 2) {
for(int i = 1;i <= k;++ i)
R[id][i] = -N , L[id][i] = N;
L[id][a[l]] = R[id][a[l]] = l;
if(k == 1)
dp[id] = 1;
return ;
}
if(x < md)
Update(x , l , md , lc);
else
Update(x , md , r , rc);
Merge(id);
}
void Build(int l = 1 , int r = n + 1 , int id = 1) {
dp[id] = N;
if(r - l < 2) {
for(int i = 1;i <= k;++ i)
R[id][i] = -N , L[id][i] = N;
L[id][a[l]] = R[id][a[l]] = l;
if(k == 1)
dp[id] = 1;
return ;
}
Build(l , md , lc);
Build(md , r , rc);
Merge(id);
}
int main() {
scanf("%d %d %d" , & n , & k , & q);
iota(P + 1 , P + 1 + k , 1);
for(int i = 1;i <= n;++ i)
scanf("%d" , a + i);
Build();
while(q --) {
int tp , x , y;
scanf("%d" , & tp);
if(tp == 2)
printf("%d\n" , dp[1] > n ? -1 : dp[1]);
else
scanf("%d %d" , & x , & y) , a[x] = y , Update(x);
}
return 0;
}
/*
4 3 1
1 3 3 2
2
*/
Compilation message (stderr)
nekameleoni.cpp: In function 'int main()':
nekameleoni.cpp:62:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d" , & n , & k , & q);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nekameleoni.cpp:65:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d" , a + i);
~~~~~^~~~~~~~~~~~~~
nekameleoni.cpp:69:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d" , & tp);
~~~~~^~~~~~~~~~~~~
nekameleoni.cpp:73:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d" , & x , & y) , a[x] = y , Update(x);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# | 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... |