#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, K, Q;
const ll INF = 1e18;
struct Node{
ll len, ans;
vector<ll> L, R;
Node(){}
Node(ll _len, ll _ans){len = _len, ans = _ans; L.resize(55, INF); R.resize(55, -INF);}
};
Node f(Node &p, Node &q){
Node ret(p.len + q.len, min(p.ans, q.ans));
for(ll 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]);
}
vector<pair<ll, ll>> V;
for(ll i = 1; i <= K; i++){
V.push_back({p.R[i], i});
}
sort(V.begin(), V.end());
ll r = -1;
for(ll i = 0; i < (ll)V.size() - 1; i++){
if(q.L[V[i].second] == -INF) break;
r = max(r, q.L[V[i].second]);
ret.ans = min(ret.ans, r - V[i + 1].first + 1);
}
return ret;
}
Node T[400005];
void update(ll n, ll s, ll e, ll k, ll v){
if(s == e){
T[n] = Node(1, (K == 1 ? 1 : INF));
T[n].L[v] = T[n].R[v] = k;
return;
}
ll 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(1, INF));
cin >> N >> K >> Q;
for(ll i = 1; i <= N; i++){
ll v; cin >> v;
update(1, 1, N, i, v);
}
while(Q--){
ll op; cin >> op;
if(op == 1){
ll 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 |
Correct |
215 ms |
375940 KB |
Output is correct |
2 |
Correct |
219 ms |
376040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
286 ms |
376140 KB |
Output is correct |
2 |
Correct |
306 ms |
376012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
382 ms |
376048 KB |
Output is correct |
2 |
Correct |
402 ms |
376040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1659 ms |
376300 KB |
Output is correct |
2 |
Execution timed out |
3093 ms |
376176 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3095 ms |
376132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3103 ms |
376116 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3083 ms |
376068 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3105 ms |
376176 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3092 ms |
376008 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3103 ms |
375984 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |