#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
using ii = pair<int, int>;
const int inf = 1e9;
const ii EMPTY = {-inf, inf};
ii merge(ii first, ii second) {
if(first.X > second.Y)
return {second.Y, second.Y};
if(first.Y < second.X)
return {second.X, second.X};
return {max(first.X, second.X), min(first.Y, second.Y)};
}
int doop(int x, ii op) {
return min(max(x, op.X), op.Y);
}
struct SegmentTree {
int lv;
vector<ii> lazy;
void init(int n) {
lv = 2;
while(lv < n)
lv *= 2;
lazy.resize(2 * lv + 2, EMPTY);
}
void push(int w, int l, int r) {
if(l != r) {
lazy[2 * w] = merge(lazy[2 * w], lazy[w]);
lazy[2 * w + 1] = merge(lazy[2 * w + 1], lazy[w]);
lazy[w] = EMPTY;
}
}
void insert(int a, int b, int w, int l, int r, ii op) {
push(w, l, r);
if(l > r || l > b || r < a)
return ;
if(a <= l && r <= b) {
lazy[w] = merge(lazy[w], op);
push(w, l, r);
return ;
}
insert(a, b, 2 * w, l, (l + r) / 2, op);
insert(a, b, 2 * w + 1, (l + r) / 2 + 1, r, op);
}
void insert(int a, int b, ii op) {
insert(a, b, 1, 0, lv - 1, op);
}
void push_all(int w, int l, int r) {
push(w, l, r);
if(l != r) {
push_all(2 * w, l, (l + r) / 2);
push_all(2 * w + 1, (l + r) / 2 + 1, r);
}
}
vector<int> calc() {
vector<int> res;
res.resize(lv);
push_all(1, 0, lv - 1);
//~ for(int i = 0 ; i < 2 * lv ; i++)
//~ cout << i << " " << lazy[i].X << " " << lazy[i].Y << endl;
//~ cout << endl;
for(int i = 0 ; i < lv ; i++)
res[i] = lazy[lv + i].X;
return res;
}
};
SegmentTree ST;
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
ST.init(n);
for(int i = 0 ; i < k ; i++) {
if(op[i] == 1)
ST.insert(left[i], right[i], {height[i], inf});
else
ST.insert(left[i], right[i], {-inf, height[i]});
//~ for(int i = 0 ; i < 2 * ST.lv ; i++)
//~ cout << i << " " << ST.lazy[i].X << " " << ST.lazy[i].Y << endl;
//~ cout << endl;
}
vector<int> res = ST.calc();
for(int i = 0 ; i < n ; i++)
finalHeight[i] = max(0, res[i]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
8 ms |
1024 KB |
Output is correct |
5 |
Correct |
6 ms |
896 KB |
Output is correct |
6 |
Correct |
6 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
173 ms |
13944 KB |
Output is correct |
3 |
Correct |
230 ms |
8108 KB |
Output is correct |
4 |
Correct |
682 ms |
20856 KB |
Output is correct |
5 |
Correct |
383 ms |
21492 KB |
Output is correct |
6 |
Correct |
379 ms |
19904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
10 ms |
928 KB |
Output is correct |
5 |
Correct |
7 ms |
896 KB |
Output is correct |
6 |
Correct |
6 ms |
896 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
180 ms |
13968 KB |
Output is correct |
9 |
Correct |
228 ms |
8184 KB |
Output is correct |
10 |
Correct |
649 ms |
20920 KB |
Output is correct |
11 |
Correct |
383 ms |
21492 KB |
Output is correct |
12 |
Correct |
370 ms |
19956 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
178 ms |
14040 KB |
Output is correct |
15 |
Correct |
47 ms |
2168 KB |
Output is correct |
16 |
Correct |
807 ms |
20772 KB |
Output is correct |
17 |
Correct |
402 ms |
20204 KB |
Output is correct |
18 |
Correct |
395 ms |
20232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
8 ms |
896 KB |
Output is correct |
5 |
Correct |
6 ms |
896 KB |
Output is correct |
6 |
Correct |
6 ms |
896 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
176 ms |
13944 KB |
Output is correct |
9 |
Correct |
263 ms |
8188 KB |
Output is correct |
10 |
Correct |
753 ms |
20776 KB |
Output is correct |
11 |
Correct |
381 ms |
21492 KB |
Output is correct |
12 |
Correct |
373 ms |
19956 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
194 ms |
14072 KB |
Output is correct |
15 |
Correct |
43 ms |
2168 KB |
Output is correct |
16 |
Correct |
781 ms |
20856 KB |
Output is correct |
17 |
Correct |
378 ms |
20216 KB |
Output is correct |
18 |
Correct |
377 ms |
20216 KB |
Output is correct |
19 |
Correct |
921 ms |
69476 KB |
Output is correct |
20 |
Correct |
904 ms |
67448 KB |
Output is correct |
21 |
Correct |
928 ms |
69544 KB |
Output is correct |
22 |
Correct |
906 ms |
67560 KB |
Output is correct |
23 |
Correct |
929 ms |
67448 KB |
Output is correct |
24 |
Correct |
1087 ms |
67448 KB |
Output is correct |
25 |
Correct |
884 ms |
67576 KB |
Output is correct |
26 |
Correct |
896 ms |
69604 KB |
Output is correct |
27 |
Correct |
891 ms |
69604 KB |
Output is correct |
28 |
Correct |
895 ms |
67704 KB |
Output is correct |
29 |
Correct |
926 ms |
67576 KB |
Output is correct |
30 |
Correct |
893 ms |
67484 KB |
Output is correct |