#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
#include <cmath>
#include <map>
#include <random>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <limits.h>
using namespace std;
class Node {
public:
vector<int> left, right;
bool okay = true;
Node () {
left.assign(51, INT_MAX), right.assign(51, -1);
}
};
vector<int64_t> powr;
Node generate (int t, int64_t x) {
Node ans;
ans.left[x] = t;
ans.left[0] = 0;
ans.right[x] = t;
ans.right[0] = 0;
return ans;
}
int finder (vector<int> v1, vector<int> v2, int K) {
set<int> s;
for (int i = 1; i <= K; i++) {
if (v1[i] == -1 || v1[i] == INT_MAX) return -1;
s.insert(v1[i]);
}
for (int i = 1; i <= K; i++) {
if (v2[i] == -1 || v2[i] == INT_MAX) return -1;
s.insert(v2[i]);
}
int ans = INT_MAX;
for (int i: s) {
for (int j: s) {
bool fine = true;
for (int k = 1; k <= K; k++) {
if ((v1[k] < i || v1[k] > j) && (v2[k] < i || v2[k] > j)) {
fine = false; break;
}
}
if (fine) {
ans = min(ans, abs(j-i));
}
}
}
return ans + 1;
}
Node merge (Node x, Node y) {
if (!x.okay) return y;
if (!y.okay) return x;
Node ans;
ans.left = x.left;
ans.right = y.right;
for (int i = 0; i <= 50; i++) {
ans.left[i] = min(x.left[i], y.left[i]);
}
for (int i = 0; i <= 50; i++) {
ans.right[i] = max(x.right[i], y.right[i]);
}
return ans;
}
template<class T>
class SegmentTree {
public:
SegmentTree (int N) {
N = (1 << ((int)floor(log2(N - 1)) + 1));
this->N = N;
val.assign(2 * N, ID);
ID.okay = false;
}
void update (int x, T y) {
x += N - 1;
val[x] = y;
while (x != 0) {
x = (x - 1)/2;
val[x] = merge(val[2 * x + 1], val[2 * x + 2]);
}
}
void build (int dum, vector<int>& arr, int tl, int tr) {
if (tl == tr) {
if (tl < arr.size()) val[dum] = generate(tl, arr[tl]);
else val[dum] = generate(tl, 0);
return;
}
build(2 * dum + 1, arr, tl, (tl + tr)/2);
build(2 * dum + 2, arr, (tl + tr)/2 + 1, tr);
val[dum] = merge(val[2 * dum + 1], val[2 * dum + 2]);
}
void build (vector<int> arr) {
build(0, arr, 0, N - 1);
}
T query (int ind, const int l, const int r, int tl, int tr) {
if (tl >= l && tr <= r) {
return val[ind];
}
if (tr < l || tl > r) {
return ID;
}
return merge(query(2 * ind + 1, l, r, tl, (tl + tr)/2), query(2 * ind + 2, l, r, (tl + tr)/2 + 1, tr));
}
T query (int l, int r) {
return query(0, l, r, 0, N - 1);
}
private:
vector<T> val;
T ID;
int N;
};
int main() {
//freopen("balancing.in", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, K, M;
cin >> N >> K >> M;
SegmentTree<Node> st(N);
vector<int> arr(N);
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
powr = {1};
for (int i = 0; i < 50; i++) {
powr.push_back(powr.back() * 2);
}
st.build(arr);
while (M--) {
int t; cin >> t;
if (t == 2) {
Node myNode = st.query(0, N - 1);
cout << finder(myNode.left, myNode.right, K) << '\n';
} else {
int p, v; cin >> p >> v; p--;
st.update(p, generate(p, v));
}
}
}
Compilation message
nekameleoni.cpp: In instantiation of 'void SegmentTree<T>::build(int, std::vector<int>&, int, int) [with T = Node]':
nekameleoni.cpp:104:14: required from 'void SegmentTree<T>::build(std::vector<int>) [with T = Node]'
nekameleoni.cpp:140:17: required from here
nekameleoni.cpp:94:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | if (tl < arr.size()) val[dum] = generate(tl, arr[tl]);
| ~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
4400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
79 ms |
8404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
202 ms |
8404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1801 ms |
32968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2267 ms |
65484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3075 ms |
65808 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3073 ms |
65996 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3073 ms |
65744 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3071 ms |
130696 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3039 ms |
130672 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |