// IOI 2014 - Wall
#include <bits/stdc++.h>
#include "wall.h"
using namespace std;
typedef pair <int, int> node;
#define Min first
#define Max second
const int N = 2000010;
const int INF = 1e9 + 10;
node tree[4 * N];
void push (int u, int b, int e) {
if (b == e) return;
int l = u << 1, r = l | 1;
tree[l].Min = min(tree[l].Min, tree[u].Min);
tree[l].Min = max(tree[l].Min, tree[u].Max);
tree[l].Max = min(tree[l].Max, tree[u].Min);
tree[l].Max = max(tree[l].Max, tree[u].Max);
tree[r].Min = min(tree[r].Min, tree[u].Min);
tree[r].Min = max(tree[r].Min, tree[u].Max);
tree[r].Max = min(tree[r].Max, tree[u].Min);
tree[r].Max = max(tree[r].Max, tree[u].Max);
}
void update (int u, int b, int e, int from, int to, int v, int type) {
push(u, b, e);
if (b > to or e < from) return;
if (b >= from and e <= to) {
if (type) {
tree[u].Min = min(tree[u].Min, v);
tree[u].Max = min(tree[u].Max, v);
} else {
tree[u].Min = max(tree[u].Min, v);
tree[u].Max = max(tree[u].Max, v);
}
return;
}
tree[u].Min = INF, tree[u].Max = -INF;
int l = u << 1, r = l | 1, m = b + e >> 1;
update(l, b, m, from, to, v, type);
update(r, m + 1, e, from, to, v, type);
}
void traverse (int u, int b, int e, int res[]) {
if (b == e) {
res[b - 1] = tree[u].Min;
return;
}
push(u, b, e);
int l = u << 1, r = l | 1, m = b + e >> 1;
traverse(l, b, m, res), traverse(r, m + 1, e, res);
}
void buildWall (int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
for (int i = 0; i < k; ++i) {
update(1, 1, n, left[i] + 1, right[i] + 1, height[i], op[i] - 1);
}
traverse(1, 1, n, finalHeight);
return;
}
Compilation message
wall.cpp: In function 'void update(int, int, int, int, int, int, int)':
wall.cpp:45:36: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int l = u << 1, r = l | 1, m = b + e >> 1;
^
wall.cpp: In function 'void traverse(int, int, int, int*)':
wall.cpp:56:36: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int l = u << 1, r = l | 1, m = b + e >> 1;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
64520 KB |
Output is correct |
2 |
Correct |
0 ms |
64656 KB |
Output is correct |
3 |
Correct |
0 ms |
64520 KB |
Output is correct |
4 |
Correct |
6 ms |
64656 KB |
Output is correct |
5 |
Correct |
6 ms |
64656 KB |
Output is correct |
6 |
Correct |
6 ms |
64656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
64520 KB |
Output is correct |
2 |
Correct |
196 ms |
72344 KB |
Output is correct |
3 |
Correct |
226 ms |
67916 KB |
Output is correct |
4 |
Correct |
679 ms |
72736 KB |
Output is correct |
5 |
Correct |
433 ms |
72736 KB |
Output is correct |
6 |
Correct |
426 ms |
72736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
64520 KB |
Output is correct |
2 |
Correct |
0 ms |
64656 KB |
Output is correct |
3 |
Correct |
0 ms |
64520 KB |
Output is correct |
4 |
Correct |
6 ms |
64656 KB |
Output is correct |
5 |
Correct |
3 ms |
64656 KB |
Output is correct |
6 |
Correct |
6 ms |
64656 KB |
Output is correct |
7 |
Correct |
0 ms |
64520 KB |
Output is correct |
8 |
Correct |
173 ms |
72344 KB |
Output is correct |
9 |
Correct |
249 ms |
67916 KB |
Output is correct |
10 |
Correct |
749 ms |
72736 KB |
Output is correct |
11 |
Correct |
423 ms |
72736 KB |
Output is correct |
12 |
Correct |
439 ms |
72736 KB |
Output is correct |
13 |
Correct |
0 ms |
64520 KB |
Output is correct |
14 |
Correct |
216 ms |
72344 KB |
Output is correct |
15 |
Correct |
39 ms |
65148 KB |
Output is correct |
16 |
Correct |
739 ms |
72736 KB |
Output is correct |
17 |
Correct |
449 ms |
72736 KB |
Output is correct |
18 |
Correct |
386 ms |
72736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
64520 KB |
Output is correct |
2 |
Correct |
0 ms |
64656 KB |
Output is correct |
3 |
Correct |
0 ms |
64520 KB |
Output is correct |
4 |
Correct |
9 ms |
64656 KB |
Output is correct |
5 |
Correct |
9 ms |
64656 KB |
Output is correct |
6 |
Correct |
9 ms |
64656 KB |
Output is correct |
7 |
Correct |
0 ms |
64520 KB |
Output is correct |
8 |
Correct |
209 ms |
72344 KB |
Output is correct |
9 |
Correct |
236 ms |
67916 KB |
Output is correct |
10 |
Correct |
696 ms |
72736 KB |
Output is correct |
11 |
Correct |
366 ms |
72736 KB |
Output is correct |
12 |
Correct |
433 ms |
72736 KB |
Output is correct |
13 |
Correct |
0 ms |
64520 KB |
Output is correct |
14 |
Correct |
176 ms |
72344 KB |
Output is correct |
15 |
Correct |
49 ms |
65148 KB |
Output is correct |
16 |
Correct |
689 ms |
72736 KB |
Output is correct |
17 |
Correct |
429 ms |
72736 KB |
Output is correct |
18 |
Correct |
403 ms |
72736 KB |
Output is correct |
19 |
Correct |
923 ms |
80160 KB |
Output is correct |
20 |
Correct |
846 ms |
80160 KB |
Output is correct |
21 |
Correct |
823 ms |
80160 KB |
Output is correct |
22 |
Correct |
906 ms |
80160 KB |
Output is correct |
23 |
Correct |
919 ms |
80160 KB |
Output is correct |
24 |
Correct |
896 ms |
80160 KB |
Output is correct |
25 |
Correct |
869 ms |
80160 KB |
Output is correct |
26 |
Correct |
883 ms |
80160 KB |
Output is correct |
27 |
Correct |
899 ms |
80160 KB |
Output is correct |
28 |
Correct |
959 ms |
80160 KB |
Output is correct |
29 |
Correct |
869 ms |
80160 KB |
Output is correct |
30 |
Correct |
956 ms |
80160 KB |
Output is correct |