# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1006603 |
2024-06-24T05:04:42 Z |
farrellw |
Wall (IOI14_wall) |
C++14 |
|
0 ms |
348 KB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define INF 1000000
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#include "wall.h"
ii combine(ii upd_new, ii upd_old) { // apply upd_new to upd_old
ii res = {max(upd_new.fi, upd_old.fi), min(upd_new.se, upd_old.se)};
if (res.fi > res.se) { // The ranges are disjoint, so suffices to check either
res = (upd_old.se < upd_new.se) ? make_pair(upd_new.fi, upd_new.fi) : make_pair(upd_new.se, upd_new.se);
}
return res;
}
struct Segtree { // Segtree of updates
int sz;
vector<ii> upd; // store (a, b)
Segtree(int N) {
sz = N+10;
//while (sz < N)
// sz *= 2;
upd = vii(2 * sz, {0, INF});
}
void push(int id, int left, int right) { // O(1), for regular updates
if (right - left == 1)
return;
upd[2 * id + 1] = combine(upd[id], upd[2 * id + 1]);
upd[2 * id + 2] = combine(upd[id], upd[2 * id + 2]);
upd[id] = {0, INF};
}
void push_recursive(int id, int left, int right) { // O(N), only for answer extraction at the end
if(right - left == 1)
return;
push(id, left, right);
int mid = (left + right) / 2;
push_recursive(2 * id + 1, left, mid);
push_recursive(2 * id + 2, mid, right);
}
void range_upd(int qleft, int qright, ii val, int id, int left, int right) {
if (qleft <= left && right <= qright) {
upd[id] = combine(val, upd[id]);
return;
}
if (qright <= left || right <= qleft)
return;
push(id, left, right);
int mid = (left + right) / 2;
range_upd(qleft, qright, val, 2 * id + 1, left, mid);
range_upd(qleft, qright, val, 2 * id + 2, mid, right);
}
void range_upd(int qleft, int qright, ii val) {
range_upd(qleft, qright, val, 0, 0, sz);
}
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
Segtree tree(n);
for(int z = 0; z < k; z++) {
ii upd_val = (op[z] == 1) ? make_pair(height[z], INF) : make_pair(0, height[z]);
tree.range_upd(left[z], right[z]+1, upd_val);
}
tree.push_recursive(0, 0, tree.sz);
for(int z = 0; z < n; z++) {
finalHeight[z] = tree.upd[z+tree.sz-1].fi;
}
return;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |