답안 #999677

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
999677 2024-06-16T04:40:35 Z 정민찬(#10837) 벽 (IOI14_wall) C++14
100 / 100
886 ms 102484 KB
#include "wall.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int inf = 1e9;

struct Node{
	int low, hi;
};

struct SegmentTree{
	vector<Node> tree;
	vector<Node> lazy;
	void init(int n) {
		int sz = 1 << __lg(n-1) + 2;
		tree.assign(sz, {0, 0});
		lazy.assign(sz, {0, inf});
	}
	void propagate(int node, int s, int e) {
		tree[node].low = max(tree[node].low, lazy[node].low);
		tree[node].hi = max(tree[node].hi, lazy[node].hi);
		tree[node].low = min(tree[node].low, lazy[node].hi);
		tree[node].hi = min(tree[node].hi, lazy[node].hi);
		if (s != e) {
			for (auto &i : {node*2, node*2+1}) {
				lazy[i].low = max(lazy[i].low, lazy[node].low);
				lazy[i].hi = max(lazy[i].hi, lazy[node].low);
				lazy[i].low = min(lazy[i].low, lazy[node].hi);
				lazy[i].hi = min(lazy[i].hi, lazy[node].hi);
			}
		}
		lazy[node] = {0, inf};
	}
	void update(int node, int s, int e, int l, int r, int val, int op) {
		propagate(node, s, e);
		if (l > e || s > r) return;
		if (l <= s && e <= r) {
			if (op == 1) {
				lazy[node].low = val;				
			}
			else {
				lazy[node].hi = val;
			}
			propagate(node, s, e);
			return;
		}
		int mid = s + e >> 1;
		update(node*2, s, mid, l, r, val, op);
		update(node*2+1, mid+1, e, l, r, val, op);
	}
	void getAns(int node, int s, int e, int finalHeight[]) {
		propagate(node, s, e);
		if (s == e) {
			finalHeight[s-1] = tree[node].low;
			return;
		}
		int mid = s + e >> 1;
		getAns(node*2, s, mid, finalHeight);
		getAns(node*2+1, mid+1, e, finalHeight);
	}
};

SegmentTree seg;

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
	seg.init(n);
	for (int i=0; i<k; i++) {
		seg.update(1, 1, n, left[i] + 1, right[i] + 1, height[i], op[i]);
	}
	seg.getAns(1, 1, n, finalHeight);
}

Compilation message

wall.cpp: In member function 'void SegmentTree::init(int)':
wall.cpp:17:27: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   17 |   int sz = 1 << __lg(n-1) + 2;
      |                 ~~~~~~~~~~^~~
wall.cpp: In member function 'void SegmentTree::update(int, int, int, int, int, int, int)':
wall.cpp:49:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |   int mid = s + e >> 1;
      |             ~~^~~
wall.cpp: In member function 'void SegmentTree::getAns(int, int, int, int*)':
wall.cpp:59:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |   int mid = s + e >> 1;
      |             ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 6 ms 1116 KB Output is correct
5 Correct 5 ms 1112 KB Output is correct
6 Correct 5 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 84 ms 14064 KB Output is correct
3 Correct 187 ms 7300 KB Output is correct
4 Correct 512 ms 22324 KB Output is correct
5 Correct 307 ms 23440 KB Output is correct
6 Correct 287 ms 22044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 7 ms 1116 KB Output is correct
5 Correct 5 ms 1144 KB Output is correct
6 Correct 5 ms 1116 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 83 ms 13856 KB Output is correct
9 Correct 177 ms 8532 KB Output is correct
10 Correct 532 ms 22352 KB Output is correct
11 Correct 303 ms 23548 KB Output is correct
12 Correct 300 ms 21844 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 87 ms 13908 KB Output is correct
15 Correct 28 ms 2640 KB Output is correct
16 Correct 521 ms 22612 KB Output is correct
17 Correct 306 ms 22096 KB Output is correct
18 Correct 318 ms 22140 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 348 KB Output is correct
4 Correct 6 ms 1116 KB Output is correct
5 Correct 5 ms 1168 KB Output is correct
6 Correct 5 ms 1116 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 93 ms 13908 KB Output is correct
9 Correct 181 ms 8540 KB Output is correct
10 Correct 516 ms 22492 KB Output is correct
11 Correct 305 ms 23376 KB Output is correct
12 Correct 297 ms 21912 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 84 ms 13904 KB Output is correct
15 Correct 28 ms 2496 KB Output is correct
16 Correct 527 ms 22868 KB Output is correct
17 Correct 299 ms 22360 KB Output is correct
18 Correct 294 ms 22352 KB Output is correct
19 Correct 765 ms 102484 KB Output is correct
20 Correct 755 ms 99728 KB Output is correct
21 Correct 734 ms 102484 KB Output is correct
22 Correct 872 ms 99924 KB Output is correct
23 Correct 773 ms 99924 KB Output is correct
24 Correct 886 ms 100120 KB Output is correct
25 Correct 708 ms 99884 KB Output is correct
26 Correct 736 ms 102284 KB Output is correct
27 Correct 818 ms 102292 KB Output is correct
28 Correct 750 ms 99920 KB Output is correct
29 Correct 799 ms 99732 KB Output is correct
30 Correct 738 ms 99924 KB Output is correct