# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1006593 |
2024-06-24T04:43:08 Z |
farrellw |
Wall (IOI14_wall) |
C++17 |
|
409 ms |
54352 KB |
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define INF 1000000
typedef long long ll;
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
//cout << "combining " << upd_new.fi << " " << upd_new.se << " on top of " << upd_old.fi << " " << upd_old.se << endl;
ii res = {max(upd_new.fi, upd_old.fi), min(upd_new.se, upd_old.se)};
if (res.fi > res.se) {
if (upd_old.se < upd_new.se) // The ranges are disjoint, so suffices to check either
res = {upd_new.fi, upd_new.fi};
else
res = {upd_new.se, upd_new.se};
}
//cout << "result is " << res.fi << " " << res.se << endl;
return res;
}
struct Segtree { // Segtree of updates
int sz;
vector<ii> upd; // store (a, b)
Segtree(int N) {
sz = 1;
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) {
//cout << "update " << id << " " << left << " " << right << " " << val.fi << " " << val.se << endl;
upd[id] = combine(val, upd[id]);
//cout << upd[id].fi << " " << upd[id].se << endl;
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]);
//cout << left[z] << " " << right[z]+1 << " " << upd_val.fi << " " << upd_val.se << "\n" << endl;
tree.range_upd(left[z], right[z]+1, upd_val);
/*for(int i = 0; i< n; i++) {
cout << tree.upd[i].fi << " ";
}
cout << endl;*/
}
tree.push_recursive(0, 0, tree.sz);
//cout << tree.sz << endl;
for(int z = 0; z < n; z++) {
finalHeight[z] = tree.upd[z+tree.sz-1].fi;
}
return;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
860 KB |
Output is correct |
5 |
Correct |
3 ms |
860 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
80 ms |
11172 KB |
Output is correct |
3 |
Correct |
105 ms |
6224 KB |
Output is correct |
4 |
Correct |
372 ms |
15768 KB |
Output is correct |
5 |
Correct |
179 ms |
15952 KB |
Output is correct |
6 |
Correct |
178 ms |
15188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
572 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
860 KB |
Output is correct |
5 |
Correct |
3 ms |
860 KB |
Output is correct |
6 |
Correct |
5 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
80 ms |
11300 KB |
Output is correct |
9 |
Correct |
105 ms |
6224 KB |
Output is correct |
10 |
Correct |
362 ms |
15700 KB |
Output is correct |
11 |
Correct |
216 ms |
15896 KB |
Output is correct |
12 |
Correct |
177 ms |
15140 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
84 ms |
11140 KB |
Output is correct |
15 |
Correct |
22 ms |
1968 KB |
Output is correct |
16 |
Correct |
409 ms |
15760 KB |
Output is correct |
17 |
Correct |
264 ms |
15444 KB |
Output is correct |
18 |
Correct |
194 ms |
15344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
444 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
4 ms |
888 KB |
Output is correct |
5 |
Correct |
3 ms |
860 KB |
Output is correct |
6 |
Correct |
3 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
81 ms |
11100 KB |
Output is correct |
9 |
Correct |
105 ms |
6300 KB |
Output is correct |
10 |
Correct |
364 ms |
15636 KB |
Output is correct |
11 |
Correct |
176 ms |
15952 KB |
Output is correct |
12 |
Correct |
164 ms |
15204 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
71 ms |
11188 KB |
Output is correct |
15 |
Correct |
21 ms |
1884 KB |
Output is correct |
16 |
Correct |
370 ms |
15712 KB |
Output is correct |
17 |
Correct |
168 ms |
15444 KB |
Output is correct |
18 |
Correct |
173 ms |
15348 KB |
Output is correct |
19 |
Correct |
377 ms |
54096 KB |
Output is correct |
20 |
Correct |
354 ms |
54104 KB |
Output is correct |
21 |
Correct |
372 ms |
54184 KB |
Output is correct |
22 |
Correct |
348 ms |
54100 KB |
Output is correct |
23 |
Correct |
359 ms |
54352 KB |
Output is correct |
24 |
Correct |
351 ms |
54156 KB |
Output is correct |
25 |
Correct |
345 ms |
54092 KB |
Output is correct |
26 |
Correct |
371 ms |
54160 KB |
Output is correct |
27 |
Correct |
346 ms |
54100 KB |
Output is correct |
28 |
Correct |
343 ms |
54096 KB |
Output is correct |
29 |
Correct |
354 ms |
54096 KB |
Output is correct |
30 |
Correct |
361 ms |
54100 KB |
Output is correct |