답안 #30906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
30906 2017-08-01T01:56:43 Z h0ngjun7 벽 (IOI14_wall) C++14
100 / 100
1109 ms 87072 KB
#include "wall.h"
#include <algorithm>
using namespace std;

const int MAXN = 2000005;

struct SEG {
	int max, min;
} seg[4 * MAXN];

int n;

void push(int x) {
	int L = x * 2, R = x * 2 + 1;
	seg[L].min = min(max(seg[L].min, seg[x].min), seg[x].max);
	seg[R].min = min(max(seg[R].min, seg[x].min), seg[x].max);
	seg[L].max = max(min(seg[L].max, seg[x].max), seg[x].min);
	seg[R].max = max(min(seg[R].max, seg[x].max), seg[x].min);
}

void query(int x, int s, int e, int l, int r, int h, int op) {
	if (s > e) return;
	if (e < l || r < s) return;
	if (l <= s && e <= r) {
		if (op == 1) {
			seg[x].min = max(seg[x].min, h);
			seg[x].max = max(seg[x].max, h);
		}
		else {
			seg[x].max = min(seg[x].max, h);
			seg[x].min = min(seg[x].min, h);
		}
		if (s < e) push(x);
		return;
	}
	if (s < e) {
		int m = (s + e) / 2;
		push(x);
		query(x * 2, s, m, l, r, h, op);
		query(x * 2 + 1, m + 1, e, l, r, h, op);
		seg[x].max = max(seg[x * 2].max, seg[x * 2 + 1].max);
		seg[x].min = min(seg[x * 2].min, seg[x * 2 + 1].min);
	}
}

int ans[MAXN];
void dfs(int x, int s, int e) {
	if (s > e) return;
	if (s == e) {
		ans[s] = seg[x].max;
		return;
	}
	push(x);
	int m = (s + e) / 2;
	dfs(x * 2, s, m);
	dfs(x * 2 + 1, m + 1, e);
}

void buildWall(int _n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
	n = _n;
	for (int i = 0; i < k; i++) {
		query(1, 0, n - 1, left[i], right[i], height[i], op[i]);
	}
	dfs(1, 0, n - 1);
	for (int i = 0; i < n; i++) finalHeight[i] = ans[i];
	return;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 71432 KB Output is correct
2 Correct 0 ms 71432 KB Output is correct
3 Correct 0 ms 71432 KB Output is correct
4 Correct 6 ms 71432 KB Output is correct
5 Correct 3 ms 71432 KB Output is correct
6 Correct 3 ms 71432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 71432 KB Output is correct
2 Correct 169 ms 79256 KB Output is correct
3 Correct 259 ms 74680 KB Output is correct
4 Correct 746 ms 79648 KB Output is correct
5 Correct 379 ms 79648 KB Output is correct
6 Correct 389 ms 79648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 71432 KB Output is correct
2 Correct 0 ms 71432 KB Output is correct
3 Correct 0 ms 71432 KB Output is correct
4 Correct 6 ms 71432 KB Output is correct
5 Correct 3 ms 71432 KB Output is correct
6 Correct 3 ms 71432 KB Output is correct
7 Correct 0 ms 71432 KB Output is correct
8 Correct 166 ms 79256 KB Output is correct
9 Correct 213 ms 74680 KB Output is correct
10 Correct 789 ms 79648 KB Output is correct
11 Correct 409 ms 79648 KB Output is correct
12 Correct 416 ms 79648 KB Output is correct
13 Correct 0 ms 71432 KB Output is correct
14 Correct 196 ms 79256 KB Output is correct
15 Correct 36 ms 71920 KB Output is correct
16 Correct 769 ms 79648 KB Output is correct
17 Correct 413 ms 79648 KB Output is correct
18 Correct 433 ms 79648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 71432 KB Output is correct
2 Correct 0 ms 71432 KB Output is correct
3 Correct 0 ms 71432 KB Output is correct
4 Correct 6 ms 71432 KB Output is correct
5 Correct 6 ms 71432 KB Output is correct
6 Correct 6 ms 71432 KB Output is correct
7 Correct 0 ms 71432 KB Output is correct
8 Correct 176 ms 79256 KB Output is correct
9 Correct 266 ms 74680 KB Output is correct
10 Correct 826 ms 79648 KB Output is correct
11 Correct 416 ms 79648 KB Output is correct
12 Correct 423 ms 79648 KB Output is correct
13 Correct 0 ms 71432 KB Output is correct
14 Correct 163 ms 79256 KB Output is correct
15 Correct 39 ms 71920 KB Output is correct
16 Correct 673 ms 79648 KB Output is correct
17 Correct 423 ms 79648 KB Output is correct
18 Correct 416 ms 79648 KB Output is correct
19 Correct 986 ms 87072 KB Output is correct
20 Correct 1109 ms 87072 KB Output is correct
21 Correct 1066 ms 87072 KB Output is correct
22 Correct 1006 ms 87072 KB Output is correct
23 Correct 986 ms 87072 KB Output is correct
24 Correct 1002 ms 87072 KB Output is correct
25 Correct 1016 ms 87072 KB Output is correct
26 Correct 1006 ms 87072 KB Output is correct
27 Correct 956 ms 87072 KB Output is correct
28 Correct 863 ms 87072 KB Output is correct
29 Correct 889 ms 87072 KB Output is correct
30 Correct 959 ms 87072 KB Output is correct