답안 #395432

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
395432 2021-04-28T10:48:27 Z Aryan_Raina 벽 (IOI14_wall) C++14
100 / 100
1394 ms 64224 KB
#include "wall.h"
#include <bits/stdc++.h>

using namespace std;

struct SegTree {
	int size = 1;
	vector<int> mx, mn;
	SegTree(int n) {
		while (size < n) size <<= 1;
		mx.resize(2*size, 0); mn.resize(2*size, 0);
	}

	void modify_op(int x, int t, int v) {
		if (t == 1) {
			mn[x] = max(mn[x], v);
			mx[x] = max(mx[x], v);
		} else if (t == 2) {
			mn[x] = min(mn[x], v);
			mx[x] = min(mx[x], v);
		}
	}

	void propagate(int x, int lx, int rx) {
		if (rx - lx == 1) return;
		modify_op(2*x+1, 1, mn[x]);
		modify_op(2*x+2, 1, mn[x]);
		modify_op(2*x+1, 2, mx[x]);
		modify_op(2*x+2, 2, mx[x]);
	}

	void modify(int l, int r, int t, int v, int x, int lx, int rx) {
		propagate(x, lx, rx);
		if (r <= lx || rx <= l) return;
		if (l <= lx && rx <= r) return modify_op(x, t, v);
		int m = (lx + rx) >> 1;
		modify(l, r, t, v, 2*x+1, lx, m); modify(l, r, t, v, 2*x+2, m, rx);
		mx[x] = max(mx[2*x+1], mx[2*x+2]);
		mn[x] = min(mn[2*x+1], mn[2*x+2]);
	}
	void modify(int l, int r, int t, int v) { modify(l, r, t, v, 0, 0, size); }

	void calc(vector<int> &a, int x, int lx, int rx) {
		propagate(x, lx, rx);
		if (rx - lx == 1) {
			if (lx < a.size()) a[lx] = mn[x];
			return;
		}
		int m = (lx + rx) >> 1;
		calc(a, 2*x+1, lx, m); calc(a, 2*x+2, m, rx);
	}
	void calc(vector<int> &a) { return calc(a, 0, 0, size); }
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
	SegTree st(n);
	for (int i = 0; i < k; i++) {
		st.modify(left[i], right[i]+1, op[i], height[i]);
	}
	vector<int> a(n); st.calc(a);
	for (int i = 0; i < n; i++) finalHeight[i] = a[i];
	return;
}

Compilation message

wall.cpp: In member function 'void SegTree::calc(std::vector<int>&, int, int, int)':
wall.cpp:46:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |    if (lx < a.size()) a[lx] = mn[x];
      |        ~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 10 ms 772 KB Output is correct
5 Correct 10 ms 716 KB Output is correct
6 Correct 10 ms 752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 162 ms 13928 KB Output is correct
3 Correct 317 ms 7900 KB Output is correct
4 Correct 902 ms 18348 KB Output is correct
5 Correct 595 ms 18244 KB Output is correct
6 Correct 595 ms 18228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 10 ms 716 KB Output is correct
5 Correct 9 ms 812 KB Output is correct
6 Correct 9 ms 716 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 157 ms 13928 KB Output is correct
9 Correct 312 ms 7964 KB Output is correct
10 Correct 908 ms 18244 KB Output is correct
11 Correct 574 ms 18268 KB Output is correct
12 Correct 565 ms 18344 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 163 ms 13848 KB Output is correct
15 Correct 50 ms 1884 KB Output is correct
16 Correct 916 ms 18220 KB Output is correct
17 Correct 595 ms 18228 KB Output is correct
18 Correct 593 ms 18224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 9 ms 716 KB Output is correct
5 Correct 9 ms 748 KB Output is correct
6 Correct 8 ms 716 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 160 ms 13908 KB Output is correct
9 Correct 314 ms 7912 KB Output is correct
10 Correct 919 ms 18224 KB Output is correct
11 Correct 621 ms 18236 KB Output is correct
12 Correct 635 ms 18292 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 215 ms 13820 KB Output is correct
15 Correct 50 ms 1868 KB Output is correct
16 Correct 920 ms 18232 KB Output is correct
17 Correct 567 ms 18224 KB Output is correct
18 Correct 615 ms 18228 KB Output is correct
19 Correct 1353 ms 63856 KB Output is correct
20 Correct 1373 ms 64004 KB Output is correct
21 Correct 1387 ms 64120 KB Output is correct
22 Correct 1344 ms 64068 KB Output is correct
23 Correct 1394 ms 64048 KB Output is correct
24 Correct 1349 ms 64104 KB Output is correct
25 Correct 1366 ms 63988 KB Output is correct
26 Correct 1350 ms 63984 KB Output is correct
27 Correct 1360 ms 63984 KB Output is correct
28 Correct 1357 ms 63980 KB Output is correct
29 Correct 1343 ms 64092 KB Output is correct
30 Correct 1343 ms 64224 KB Output is correct