#include <bits/stdc++.h>
#include <ctime>
using namespace std;
using ll = long long;
int N, K, Q;
const int INF = 1e7;
struct Node{
int ans;
int L[55] = {}, R[55] = {};
Node(){}
Node(int _ans){ans = _ans; for(ll i = 0; i < 55; i++) L[i] = INF, R[i] = -INF;}
};
Node f(Node &p, Node &q){
Node ret(min(p.ans, q.ans));
int mnl = INF, mxl = -INF, mnr = INF, mxr = -INF;
for(int i = 1; i <= K; i++){
ret.L[i] = min(p.L[i], q.L[i]);
ret.R[i] = max(p.R[i], q.R[i]);
mnl = min(mnl, ret.L[i]), mxl = max(mxl, ret.L[i]);
mnr = min(mnr, ret.R[i]), mxr = max(mxr, ret.R[i]);
}
ret.ans = min({ret.ans, mxl - mnl + 1, mxr - mnr + 1});
return ret;
}
Node T[400005];
void update(int n, int s, int e, int k, int v){
if(s == e){
T[n] = Node(K == 1 ? 1 : INF);
T[n].L[v] = T[n].R[v] = k;
return;
}
int m = (s + e) / 2;
if(k <= m) update(n * 2, s, m, k, v);
else update(n * 2 + 1, m + 1, e, k, v);
T[n] = f(T[n * 2], T[n * 2 + 1]);
}
int main(){
cin.tie(0) -> sync_with_stdio(false);
fill(T, T + 400005, Node(K == 1 ? 1 : INF));
cin >> N >> K >> Q;
for(int i = 1; i <= N; i++){
int v; cin >> v;
update(1, 1, N, i, v);
}
while(Q--){
int op; cin >> op;
if(op == 1){
int k, v; cin >> k >> v;
update(1, 1, N, k, v);
} else {
cout << (T[1].ans > N ? -1 : T[1].ans) << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
132 ms |
174072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
137 ms |
174108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
152 ms |
174176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
353 ms |
174124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
541 ms |
174224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
598 ms |
174092 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
778 ms |
174220 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
741 ms |
174160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1052 ms |
174580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1022 ms |
174764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |