#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:
map<int,int> left;
map<int,int> right;
int64_t bor = 0;
int tot = 0;
int length = 0;
bool okay = true;
void print () {
cout << "LEFT\n";
for (auto& p: left) cout << p.first << " " << p.second << '\n';
cout << "RIGHT\n";
for (auto& p: right) cout << p.first << " " << p.second << '\n';
cout << "LENGTH\n";
cout << length << '\n';
cout << "TOT\n";
cout << tot << '\n';
cout << "BOR\n";
cout << bor << '\n';
cout << '\n';
}
};
vector<int64_t> powr;
Node generate (int64_t x) {
Node ans;
ans.left[(1 << x)] = 1;
ans.left[0] = 0;
ans.right[(1 << x)] = 1;
ans.right[0] = 0;
ans.tot = 1;
ans.bor = (1 << x);
ans.length = 1;
return ans;
}
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 (auto& p: y.left) {
if (ans.left[p.first | x.bor] == 0 || ans.left[p.first | x.bor] >= p.second + x.length) {
ans.left[p.first | x.bor] = p.second + x.length;
}
}
for (auto& p: x.right) {
if (ans.right[p.first | y.bor] == 0 || ans.right[p.first | y.bor] >= p.second + y.length) {
ans.right[p.first | y.bor] = p.second + y.length;
}
}
ans.bor = x.bor | y.bor;
ans.tot = INT_MAX;
ans.length = x.length + y.length;
if (x.bor == y.bor) {
ans.tot = min(x.tot, y.tot);
}
for (auto& p: x.right) {
for (auto& q: y.left) {
if ((p.first | q.first) == ans.bor) {
ans.tot = min(ans.tot, p.second + q.second);
}
}
}
//x.print();
//y.print();
//ans.print();
if (ans.tot == INT_MAX) {
assert(false);
}
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) {
val[dum] = generate(arr[tl]);
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() {
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++) {
//int x; cin >> x;
cin >> arr[i];
//st.update(i, generate(arr[i]));
}
st.build(arr);
powr = {1};
for (int i = 0; i < 50; i++) {
powr.push_back(powr.back() * 2);
}
while (M--) {
int t; cin >> t;
if (t == 2) {
if (st.query(0, N - 1).bor == powr[K + 1] - 2) {
cout << st.query(0, N - 1).tot << '\n';
} else {
cout << "-1\n";
}
} else {
int p, v; cin >> p >> v; p--;
st.update(p, generate(v));
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
171 ms |
3992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
481 ms |
7640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
621 ms |
7800 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3065 ms |
30544 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3026 ms |
66184 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3036 ms |
66204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3036 ms |
66536 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3097 ms |
66304 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3083 ms |
132332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3058 ms |
132356 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |