Submission #1007145

# Submission time Handle Problem Language Result Execution time Memory
1007145 2024-06-24T12:20:12 Z pawned Wall (IOI14_wall) C++17
100 / 100
733 ms 54520 KB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

#include "wall.h"

ii combine(ii p1, ii p2) {	// apply p1 on p2 (p1 is newer)
	// (a, b) [later] done on (c, d)
	// becomes (max(a, c), min(b, d))
	// if min(b, d) > max(a, c), know that [a, b] and [c, d] are disjoint
	// if b < d, then becomes (b, b); otherwise becomes (c, c)
	ii res = {max(p1.fi, p2.fi), min(p1.se, p2.se)};
	if (res.fi > res.se) {
		if (p1.se < p2.se)
			res = {p1.se, p1.se};
		else
			res = {p1.fi, p1.fi};
	}
	return res;
}

struct Segtree {	// range addition, range sum query
	int sz;
	vector<ii> lazy;	// store (a, b)
	Segtree(int N) {
		sz = 1;
		while (sz < N)
			sz *= 2;
		lazy = vector<ii>(2 * sz, {-1e9, 1e9});
	}
	void push(int id, int left, int right) {
		if (right - left == 1)
			return;
		lazy[2 * id + 1] = combine(lazy[id], lazy[2 * id + 1]);
		lazy[2 * id + 2] = combine(lazy[id], lazy[2 * id + 2]);
		lazy[id] = {-1e9, 1e9};
	}
	void range_upd(int qleft, int qright, ii val, int id, int left, int right) {
		if (qleft <= left && right <= qright) {
			lazy[id] = combine(val, lazy[id]);
			return;
		}
		if (qright <= left || right <= qleft)
			return;
		push(id, left, right);
		int mid = (left + right) / 2;
		range_upd(qleft, qright, val, 2 * id + 1, left, mid);
		range_upd(qleft, qright, val, 2 * id + 2, mid, right);
	}
	void range_upd(int qleft, int qright, ii val) {
		range_upd(qleft, qright, val, 0, 0, sz);
	}
	ii query(int pos, int id, int left, int right) {
		if (right - left == 1) {
			return lazy[id];
		}
		push(id, left, right);
		int mid = (left + right) / 2;
		if (pos < mid)
			return query(pos, 2 * id + 1, left, mid);
		else
			return query(pos, 2 * id + 2, mid, right);
	}
	ii query(int pos) {
		return query(pos, 0, 0, sz);
	}
};

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++) {
		if (op[i] == 1)
			st.range_upd(left[i], right[i] + 1, {height[i], 1e9});
		else
			st.range_upd(left[i], right[i] + 1, {-1e9, height[i]});
	}
/*	for (int i = 0; i < N; i++) {
		ii res = st.query(i);
		cout<<i<<": "<<res.fi<<" "<<res.se<<endl;
	}*/
	for (int i = 0; i < N; i++) {
		finalHeight[i] = max(st.query(i).fi, 0);
	}
	return;
}

// f(x) = a, x, or b (piecewise)
// represent function
// store as (a, b), where a can be -inf and b can be +inf

// query: returns (a, b)


// (a, b) [later] done on (c, d)
// becomes (max(a, c), min(b, d))
// if min(b, d) > max(a, c), know that [a, b] and [c, d] are disjoint
// if b < d, then becomes (b, b); otherwise becomes (c, c)
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 5 ms 860 KB Output is correct
5 Correct 4 ms 860 KB Output is correct
6 Correct 4 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 78 ms 8088 KB Output is correct
3 Correct 103 ms 6480 KB Output is correct
4 Correct 266 ms 15880 KB Output is correct
5 Correct 189 ms 16208 KB Output is correct
6 Correct 181 ms 15436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 500 KB Output is correct
4 Correct 5 ms 848 KB Output is correct
5 Correct 4 ms 860 KB Output is correct
6 Correct 4 ms 896 KB Output is correct
7 Correct 0 ms 436 KB Output is correct
8 Correct 88 ms 11600 KB Output is correct
9 Correct 95 ms 6408 KB Output is correct
10 Correct 292 ms 15948 KB Output is correct
11 Correct 188 ms 15956 KB Output is correct
12 Correct 178 ms 15460 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 87 ms 11384 KB Output is correct
15 Correct 25 ms 1884 KB Output is correct
16 Correct 427 ms 16120 KB Output is correct
17 Correct 194 ms 15444 KB Output is correct
18 Correct 196 ms 15352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 6 ms 872 KB Output is correct
5 Correct 4 ms 860 KB Output is correct
6 Correct 4 ms 1112 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 77 ms 11516 KB Output is correct
9 Correct 105 ms 6740 KB Output is correct
10 Correct 280 ms 15952 KB Output is correct
11 Correct 191 ms 16152 KB Output is correct
12 Correct 179 ms 15388 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 76 ms 11388 KB Output is correct
15 Correct 23 ms 2020 KB Output is correct
16 Correct 407 ms 15956 KB Output is correct
17 Correct 180 ms 15336 KB Output is correct
18 Correct 173 ms 15376 KB Output is correct
19 Correct 733 ms 54376 KB Output is correct
20 Correct 676 ms 54352 KB Output is correct
21 Correct 673 ms 54352 KB Output is correct
22 Correct 677 ms 54356 KB Output is correct
23 Correct 668 ms 54444 KB Output is correct
24 Correct 704 ms 54512 KB Output is correct
25 Correct 671 ms 54352 KB Output is correct
26 Correct 666 ms 54408 KB Output is correct
27 Correct 654 ms 54516 KB Output is correct
28 Correct 681 ms 54416 KB Output is correct
29 Correct 691 ms 54364 KB Output is correct
30 Correct 718 ms 54520 KB Output is correct