답안 #1081038

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081038 2024-08-29T17:18:17 Z DarkMatter 벽 (IOI14_wall) C++17
100 / 100
750 ms 120484 KB
#include "wall.h"
#include<bits/stdc++.h>
using namespace std;
struct SegmentTree
{
	int n;
	vector<int>seg;
	vector<pair<int, int>>lazy;
	SegmentTree(int _n) {
		n = _n;
		seg.resize(4 * n + 5, 0);
		lazy.resize(4 * n + 5, { 1e9 + 7,-1 });
	}
	void push(int x, int lx, int rx) {
		if (lx == rx)
			return;
		if (lazy[x].first != 1e9) {
			seg[2 * x] = min(seg[2 * x], lazy[x].first);
			lazy[2 * x].first = min(lazy[2 * x].first, lazy[x].first);
			lazy[2 * x].second = min(lazy[2 * x].second, lazy[x].first);
			seg[2 * x + 1] = min(seg[2 * x + 1], lazy[x].first);
			lazy[2 * x + 1].first = min(lazy[2 * x + 1].first, lazy[x].first);
			lazy[2 * x + 1].second = min(lazy[2 * x + 1].second, lazy[x].first);
		}
		if (lazy[x].second != -1) {
			seg[2 * x] = max(seg[2 * x], lazy[x].second);
			lazy[2 * x].first = max(lazy[2 * x].first, lazy[x].second);
			lazy[2 * x].second = max(lazy[2 * x].second, lazy[x].second);
			seg[2 * x + 1] = max(seg[2 * x + 1], lazy[x].second);
			lazy[2 * x + 1].first = max(lazy[2 * x + 1].first, lazy[x].second);
			lazy[2 * x + 1].second = max(lazy[2 * x + 1].second, lazy[x].second);
		}
		lazy[x] = { 1e9,-1 };
	}
	void update(int x, int lx, int rx, int l, int r, int type, int v) {
		push(x, lx, rx);
		if (lx > rx || l > rx || lx > r)
			return;
		if (lx >= l && rx <= r) {
			if (type == 1)
				seg[x] = max(seg[x], v), lazy[x].first = max(lazy[x].first, v), lazy[x].second = max(lazy[x].second, v);
			else
				seg[x] = min(seg[x], v), lazy[x].first = min(lazy[x].first, v), lazy[x].second = min(lazy[x].second, v);
			push(x, lx, rx);
			return;
		}
		int mid = (lx + rx) / 2;
		update(2 * x, lx, mid, l, r, type, v);
		update(2 * x + 1, mid + 1, rx, l, r, type, v);
	}
	int get(int x, int lx, int rx, int i) {
		if (lx == rx)
			return seg[x];
		push(x, lx, rx);
		int mid = (lx + rx) / 2;
		if (i <= mid)
			return get(2 * x, lx, mid, i);
		else
			return get(2 * x + 1, mid + 1, rx, i);
	}
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
	for (int i = 0; i < n; i++)
		finalHeight[i] = 0;
	SegmentTree seg(n);
	for (int i = 0; i < k; i++)
		seg.update(1, 0, n - 1, left[i], right[i], op[i], height[i]);
	for (int i = 0; i < n; i++)
		finalHeight[i] = seg.get(1, 0, n - 1, i);
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 6 ms 964 KB Output is correct
5 Correct 5 ms 1116 KB Output is correct
6 Correct 5 ms 1128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 93 ms 13840 KB Output is correct
3 Correct 152 ms 8276 KB Output is correct
4 Correct 426 ms 22868 KB Output is correct
5 Correct 218 ms 23376 KB Output is correct
6 Correct 207 ms 21756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 448 KB Output is correct
4 Correct 6 ms 1116 KB Output is correct
5 Correct 4 ms 1116 KB Output is correct
6 Correct 4 ms 1116 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 83 ms 13904 KB Output is correct
9 Correct 150 ms 8272 KB Output is correct
10 Correct 452 ms 22956 KB Output is correct
11 Correct 219 ms 23376 KB Output is correct
12 Correct 197 ms 21724 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 104 ms 13876 KB Output is correct
15 Correct 37 ms 2236 KB Output is correct
16 Correct 567 ms 22868 KB Output is correct
17 Correct 227 ms 22156 KB Output is correct
18 Correct 221 ms 22400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 2 ms 444 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 5 ms 1116 KB Output is correct
5 Correct 5 ms 892 KB Output is correct
6 Correct 5 ms 956 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 86 ms 13908 KB Output is correct
9 Correct 156 ms 8296 KB Output is correct
10 Correct 436 ms 22864 KB Output is correct
11 Correct 216 ms 23372 KB Output is correct
12 Correct 210 ms 22096 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 91 ms 14060 KB Output is correct
15 Correct 38 ms 2136 KB Output is correct
16 Correct 528 ms 22864 KB Output is correct
17 Correct 262 ms 22180 KB Output is correct
18 Correct 209 ms 22356 KB Output is correct
19 Correct 694 ms 120404 KB Output is correct
20 Correct 669 ms 120284 KB Output is correct
21 Correct 685 ms 120440 KB Output is correct
22 Correct 673 ms 120324 KB Output is correct
23 Correct 690 ms 120352 KB Output is correct
24 Correct 665 ms 120400 KB Output is correct
25 Correct 750 ms 120316 KB Output is correct
26 Correct 727 ms 120400 KB Output is correct
27 Correct 693 ms 120456 KB Output is correct
28 Correct 657 ms 120484 KB Output is correct
29 Correct 660 ms 120480 KB Output is correct
30 Correct 671 ms 120228 KB Output is correct