// 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
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 |
1 |
Correct |
14 ms |
3704 KB |
Output is correct |
2 |
Correct |
9 ms |
3704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
5496 KB |
Output is correct |
2 |
Correct |
13 ms |
5496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
7160 KB |
Output is correct |
2 |
Correct |
19 ms |
7288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
445 ms |
27512 KB |
Output is correct |
2 |
Correct |
343 ms |
92412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
721 ms |
54648 KB |
Output is correct |
2 |
Correct |
343 ms |
108408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
946 ms |
54672 KB |
Output is correct |
2 |
Correct |
392 ms |
108664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1190 ms |
54776 KB |
Output is correct |
2 |
Correct |
362 ms |
108548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1166 ms |
54776 KB |
Output is correct |
2 |
Correct |
366 ms |
108512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1461 ms |
108808 KB |
Output is correct |
2 |
Correct |
360 ms |
108536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1447 ms |
108664 KB |
Output is correct |
2 |
Correct |
369 ms |
108632 KB |
Output is correct |