Submission #385429

# Submission time Handle Problem Language Result Execution time Memory
385429 2021-04-04T08:39:56 Z aarr Wall (IOI14_wall) C++14
100 / 100
1378 ms 91776 KB
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 2000 * 1000 + 5;
int n;

pair <int, int> smin[N * 4], smax[N * 4];

void apply(int id, int qt, int h, int t) {
	if (t == 0) {
		return;
	}
	if (qt == 1) {
		if (h < smax[id].first && smin[id].second > smax[id].second && smin[id].first < h) {
			smax[id] = {h, t};
		}
		else {
			smax[id] = max(smax[id], {h, t});
		}
	}
	else {
		if (h >= smin[id].first && smin[id].second < smax[id].second && smax[id].first > h) {
			smin[id] = {h, t};
		}
		else {
			smin[id] = min(smin[id], {h, t});
		}
	}	
}

void shift(int id) {
	if (smin[id].second <= smax[id].second) {
		apply(id * 2, 2, smin[id].first, smin[id].second);
		apply(id * 2, 1, smax[id].first, smax[id].second);
		apply(id * 2 + 1, 2, smin[id].first, smin[id].second);
		apply(id * 2 + 1, 1, smax[id].first, smax[id].second);
	}
	else {
		apply(id * 2, 1, smax[id].first, smax[id].second);
		apply(id * 2, 2, smin[id].first, smin[id].second);
		apply(id * 2 + 1, 1, smax[id].first, smax[id].second);
		apply(id * 2 + 1, 2, smin[id].first, smin[id].second);
	}
	
	
	smin[id] = {N, 0};
	smax[id] = {0, 0};
}

void update(int qt, int l, int r, int h, int t, int id = 1, int s = 0, int e = n) {
	if (r <= s || e <= l) {
		return;
	}
	if (l <= s && e <= r) {
	//	cout << "72 " << id << " " << s << " " << e << " " << l << " " << r << endl;
		apply(id, qt, h, t);
		return;
	}
	int md = (s + e) / 2;
	shift(id);
	update(qt, l, r, h, t, id * 2, s, md);
	update(qt, l, r, h, t, id * 2 + 1, md, e);
}

int get(int p, int id = 1, int s = 0, int e = n) {
	if (e - s == 1) {
		if (smax[id].second >= smin[id].second || smax[id].first <= smin[id].first) {
			return smax[id].first;
		}
		return smin[id].first;
	}
	shift(id);
	int md = (s + e) / 2;
	if (p < md) {
		return get(p, id * 2, s, md);
	}
	return get(p, id * 2 + 1, md, e);
}


void buildWall(int m, int q, int op[], int left[], int right[], int height[], int finalHeight[]){
	n = m;
	for (int i = 0; i < q; i++) {
		update(op[i], left[i], right[i] + 1, height[i], i + 1);
	}
	for (int i = 0; i < n; i++) {
		finalHeight[i] = get(i);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 3 ms 364 KB Output is correct
4 Correct 11 ms 1132 KB Output is correct
5 Correct 8 ms 1132 KB Output is correct
6 Correct 8 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 189 ms 11064 KB Output is correct
3 Correct 249 ms 7788 KB Output is correct
4 Correct 741 ms 15292 KB Output is correct
5 Correct 381 ms 14420 KB Output is correct
6 Correct 359 ms 15084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 4 ms 364 KB Output is correct
4 Correct 14 ms 1132 KB Output is correct
5 Correct 11 ms 1132 KB Output is correct
6 Correct 8 ms 1132 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 161 ms 11116 KB Output is correct
9 Correct 251 ms 7660 KB Output is correct
10 Correct 770 ms 15268 KB Output is correct
11 Correct 379 ms 14288 KB Output is correct
12 Correct 357 ms 15040 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 160 ms 11116 KB Output is correct
15 Correct 51 ms 2560 KB Output is correct
16 Correct 923 ms 15548 KB Output is correct
17 Correct 368 ms 15688 KB Output is correct
18 Correct 403 ms 15788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 3 ms 364 KB Output is correct
4 Correct 11 ms 1260 KB Output is correct
5 Correct 8 ms 1132 KB Output is correct
6 Correct 8 ms 1132 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 157 ms 11116 KB Output is correct
9 Correct 250 ms 7676 KB Output is correct
10 Correct 737 ms 15376 KB Output is correct
11 Correct 386 ms 14660 KB Output is correct
12 Correct 358 ms 15084 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 165 ms 11160 KB Output is correct
15 Correct 49 ms 2540 KB Output is correct
16 Correct 915 ms 15672 KB Output is correct
17 Correct 377 ms 15800 KB Output is correct
18 Correct 370 ms 15752 KB Output is correct
19 Correct 1378 ms 89872 KB Output is correct
20 Correct 1360 ms 91696 KB Output is correct
21 Correct 1357 ms 89928 KB Output is correct
22 Correct 1354 ms 91660 KB Output is correct
23 Correct 1355 ms 91776 KB Output is correct
24 Correct 1374 ms 91644 KB Output is correct
25 Correct 1362 ms 91372 KB Output is correct
26 Correct 1374 ms 89944 KB Output is correct
27 Correct 1360 ms 89964 KB Output is correct
28 Correct 1347 ms 91552 KB Output is correct
29 Correct 1354 ms 91508 KB Output is correct
30 Correct 1359 ms 91372 KB Output is correct