답안 #817760

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
817760 2023-08-09T15:47:27 Z Temmie 송신탑 (IOI22_towers) C++17
42 / 100
1407 ms 304700 KB
#include <bits/stdc++.h>

constexpr const int MXH = (int) 1e9 + 5;

struct Sparse {
	struct Item {
		int mn = MXH, mx = -MXH, anl = 0, anr = 0, mn_ind = -1;
		static Item merge(const Item& l, const Item& r) {
			return {
				std::min(l.mn, r.mn), std::max(l.mx, r.mx),
				std::max({ l.anl, r.anl, r.mx - l.mn }), std::max({ l.anr, r.anr, l.mx - r.mx }),
				l.mn < r.mn ? l.mn_ind : r.mn_ind
			};
		}
	};
	int size;
	std::vector <std::vector <Item>> bin;
	void init(const std::vector <int>& v) {
		bin.resize(17, std::vector <Item> (size = v.size()));
		for (int i = 0; i < size; i++) bin[0][i].mn = bin[0][i].mx = v[i], bin[0][i].mn_ind = i;
		for (int b = 1; b < 17; b++)
			for (int i = 0; i + (1 << (b - 1)) < size; i++)
				bin[b][i] = Item::merge(bin[b - 1][i], bin[b - 1][i + (1 << (b - 1))]);
	}
	Item query(int l, int r) {
		Item res;
		if (l >= r || l < 0 || r >= size) return res;
		for (int b = 31 - __builtin_clz(r - l), range = r - l; ~b; l += ((range >> b) & 1) << b, b--)
			if (range & (1 << b))
				res = Item::merge(res, bin[b][l]);
		return res;
	}
};

struct PNode {
	struct Item {
		int sum = 0;
		int mn = MXH, mx = -MXH;
		static Item merge(const Item& l, const Item& r) {
			return { l.sum + r.sum, std::min(l.mn, r.mn), std::max(l.mx, r.mx) };
		}
	};
	typedef std::shared_ptr <PNode> PPNode;
	Item item;
	PPNode lc = nullptr, rc = nullptr;
	PNode(const Item& _item) : item(_item) { }
	PNode(PPNode _lc, PPNode _rc) : item(Item::merge(_lc->item, _rc->item)), lc(_lc), rc(_rc) { }
	static PPNode build(int l, int r) {
		if (!(r - l - 1)) return PPNode(new PNode({ }));
		int mid = (l + r) >> 1;
		return PPNode(new PNode(build(l, mid), build(mid, r)));
	}
	static PPNode set(PPNode node, int ind, int l, int r) {
		if (!(r - l - 1)) return PPNode(new PNode({ 1, ind, ind }));
		int mid = (l + r) >> 1;
		if (ind < mid) return PPNode(new PNode(set(node->lc, ind, l, mid), node->rc));
		return PPNode(new PNode(node->lc, set(node->rc, ind, mid, r)));
	}
	Item query(int tl, int tr, int l, int r) {
		if (l >= tr || r <= tl) return { };
		if (l >= tl && r <= tr) return item;
		int mid = (l + r) >> 1;
		return Item::merge(lc->query(tl, tr, l, mid), rc->query(tl, tr, mid, r));
	}
};

int n;
std::vector <int> h;
Sparse sparse;
std::vector <std::shared_ptr <PNode>> pst;
std::map <int, int> smp;

void init(int N, std::vector <int> H) {
	n = N + 4;
	h = H;
	h.insert(h.begin(), { 0, MXH });
	h.insert(h.end(), { MXH, 0 });
	sparse.init(h);
	std::vector <std::pair <int, int>> ord(N);
	for (int i = 2; i < n - 2; i++) ord[i - 2] = { h[i], i };
	std::sort(ord.begin(), ord.end());
	std::set <int> st = { 0, n - 1 };
	std::vector <int> tmon(n);
	for (auto [hei, i] : ord) {
		auto it = st.lower_bound(i);
		tmon[i] = std::max(0, std::min(sparse.query(*prev(it) + 1, i).mx, sparse.query(i + 1, *it).mx) - hei);
		st.insert(i);
	}
	smp[MXH] = 0;
	pst.push_back(PNode::build(0, 4 * n));
	for (int i = 2; i < n - 2; i++) ord[i - 2] = { tmon[i], i };
	std::sort(ord.rbegin(), ord.rend());
	for (auto [dv, i] : ord) {
		pst.push_back(PNode::set(pst.back(), i, 0, 4 * n));
		smp[dv] = (int) pst.size() - 1;
	}
}

int max_towers(int L, int R, int D) {
	L += 2, R += 2;
	std::shared_ptr <PNode> node = pst[smp.lower_bound(D)->second];
	PNode::Item pit = node->query(L, R + 1, 0, 4 * n);
	if (!pit.sum) {
		pit.sum++;
		pit.mn = pit.mx = sparse.query(L, R + 1).mn_ind;
	}
	int ans = pit.sum;
	ans += sparse.query(L, pit.mn).anl >= D;
	ans += sparse.query(pit.mx + 1, R + 1).anr >= D;
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 803 ms 175996 KB 807th lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1232 KB Output is correct
2 Correct 7 ms 5228 KB Output is correct
3 Correct 7 ms 5200 KB Output is correct
4 Correct 7 ms 5200 KB Output is correct
5 Correct 7 ms 5200 KB Output is correct
6 Correct 7 ms 5200 KB Output is correct
7 Correct 6 ms 5200 KB Output is correct
8 Correct 7 ms 5200 KB Output is correct
9 Correct 6 ms 5268 KB Output is correct
10 Correct 8 ms 5200 KB Output is correct
11 Correct 9 ms 5200 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 10 ms 5192 KB Output is correct
14 Correct 6 ms 5200 KB Output is correct
15 Correct 7 ms 5200 KB Output is correct
16 Correct 7 ms 5200 KB Output is correct
17 Correct 9 ms 5316 KB Output is correct
18 Correct 6 ms 5272 KB Output is correct
19 Correct 8 ms 5200 KB Output is correct
20 Correct 9 ms 5192 KB Output is correct
21 Correct 8 ms 5280 KB Output is correct
22 Correct 10 ms 5200 KB Output is correct
23 Correct 9 ms 5200 KB Output is correct
24 Correct 7 ms 5200 KB Output is correct
25 Correct 4 ms 2384 KB Output is correct
26 Correct 8 ms 5300 KB Output is correct
27 Correct 7 ms 5304 KB Output is correct
28 Correct 8 ms 5328 KB Output is correct
29 Correct 9 ms 5328 KB Output is correct
30 Correct 8 ms 5316 KB Output is correct
31 Correct 8 ms 5316 KB Output is correct
32 Correct 8 ms 5248 KB Output is correct
33 Correct 6 ms 5252 KB Output is correct
34 Correct 7 ms 5280 KB Output is correct
35 Correct 7 ms 5200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1232 KB Output is correct
2 Correct 7 ms 5228 KB Output is correct
3 Correct 7 ms 5200 KB Output is correct
4 Correct 7 ms 5200 KB Output is correct
5 Correct 7 ms 5200 KB Output is correct
6 Correct 7 ms 5200 KB Output is correct
7 Correct 6 ms 5200 KB Output is correct
8 Correct 7 ms 5200 KB Output is correct
9 Correct 6 ms 5268 KB Output is correct
10 Correct 8 ms 5200 KB Output is correct
11 Correct 9 ms 5200 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 10 ms 5192 KB Output is correct
14 Correct 6 ms 5200 KB Output is correct
15 Correct 7 ms 5200 KB Output is correct
16 Correct 7 ms 5200 KB Output is correct
17 Correct 9 ms 5316 KB Output is correct
18 Correct 6 ms 5272 KB Output is correct
19 Correct 8 ms 5200 KB Output is correct
20 Correct 9 ms 5192 KB Output is correct
21 Correct 8 ms 5280 KB Output is correct
22 Correct 10 ms 5200 KB Output is correct
23 Correct 9 ms 5200 KB Output is correct
24 Correct 7 ms 5200 KB Output is correct
25 Correct 4 ms 2384 KB Output is correct
26 Correct 8 ms 5300 KB Output is correct
27 Correct 7 ms 5304 KB Output is correct
28 Correct 8 ms 5328 KB Output is correct
29 Correct 9 ms 5328 KB Output is correct
30 Correct 8 ms 5316 KB Output is correct
31 Correct 8 ms 5316 KB Output is correct
32 Correct 8 ms 5248 KB Output is correct
33 Correct 6 ms 5252 KB Output is correct
34 Correct 7 ms 5280 KB Output is correct
35 Correct 7 ms 5200 KB Output is correct
36 Correct 486 ms 193588 KB Output is correct
37 Incorrect 544 ms 303844 KB 1st lines differ - on the 1st token, expected: '2946', found: '2945'
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1183 ms 301588 KB Output is correct
2 Correct 1247 ms 303880 KB Output is correct
3 Correct 1207 ms 303992 KB Output is correct
4 Correct 1287 ms 304652 KB Output is correct
5 Correct 1244 ms 304696 KB Output is correct
6 Correct 1238 ms 304672 KB Output is correct
7 Correct 1239 ms 304616 KB Output is correct
8 Correct 1215 ms 302292 KB Output is correct
9 Correct 1175 ms 302300 KB Output is correct
10 Correct 1182 ms 302316 KB Output is correct
11 Correct 1141 ms 302252 KB Output is correct
12 Correct 1172 ms 302360 KB Output is correct
13 Correct 1182 ms 302244 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 6 ms 5200 KB Output is correct
16 Correct 6 ms 5200 KB Output is correct
17 Correct 484 ms 303880 KB Output is correct
18 Correct 514 ms 304568 KB Output is correct
19 Correct 519 ms 304648 KB Output is correct
20 Correct 391 ms 302268 KB Output is correct
21 Correct 402 ms 302408 KB Output is correct
22 Correct 491 ms 303884 KB Output is correct
23 Correct 510 ms 304548 KB Output is correct
24 Correct 557 ms 304668 KB Output is correct
25 Correct 393 ms 302364 KB Output is correct
26 Correct 390 ms 302320 KB Output is correct
27 Correct 6 ms 5200 KB Output is correct
28 Correct 6 ms 5200 KB Output is correct
29 Correct 6 ms 5316 KB Output is correct
30 Correct 6 ms 5200 KB Output is correct
31 Correct 6 ms 5200 KB Output is correct
32 Correct 6 ms 5284 KB Output is correct
33 Correct 7 ms 5292 KB Output is correct
34 Correct 6 ms 5200 KB Output is correct
35 Correct 6 ms 5200 KB Output is correct
36 Correct 6 ms 5200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 364 ms 68196 KB Output is correct
2 Correct 1395 ms 303892 KB Output is correct
3 Correct 1315 ms 303872 KB Output is correct
4 Correct 1407 ms 304592 KB Output is correct
5 Correct 1294 ms 304660 KB Output is correct
6 Correct 1327 ms 304552 KB Output is correct
7 Correct 1372 ms 304616 KB Output is correct
8 Correct 1077 ms 302336 KB Output is correct
9 Correct 1054 ms 302304 KB Output is correct
10 Correct 1101 ms 302312 KB Output is correct
11 Correct 917 ms 302248 KB Output is correct
12 Correct 500 ms 303880 KB Output is correct
13 Correct 553 ms 304652 KB Output is correct
14 Correct 505 ms 304652 KB Output is correct
15 Correct 380 ms 302240 KB Output is correct
16 Correct 486 ms 302212 KB Output is correct
17 Correct 478 ms 293072 KB Output is correct
18 Correct 478 ms 303960 KB Output is correct
19 Correct 509 ms 303808 KB Output is correct
20 Correct 512 ms 304552 KB Output is correct
21 Correct 523 ms 304668 KB Output is correct
22 Correct 512 ms 304644 KB Output is correct
23 Correct 514 ms 304700 KB Output is correct
24 Correct 393 ms 302240 KB Output is correct
25 Correct 383 ms 302300 KB Output is correct
26 Correct 396 ms 302272 KB Output is correct
27 Correct 383 ms 302272 KB Output is correct
28 Correct 7 ms 5216 KB Output is correct
29 Correct 7 ms 5200 KB Output is correct
30 Correct 6 ms 5200 KB Output is correct
31 Correct 6 ms 5200 KB Output is correct
32 Correct 6 ms 5268 KB Output is correct
33 Correct 3 ms 2384 KB Output is correct
34 Correct 6 ms 5308 KB Output is correct
35 Correct 6 ms 5200 KB Output is correct
36 Correct 7 ms 5200 KB Output is correct
37 Correct 7 ms 5324 KB Output is correct
38 Correct 8 ms 5200 KB Output is correct
39 Correct 7 ms 5200 KB Output is correct
40 Correct 6 ms 5220 KB Output is correct
41 Correct 6 ms 5200 KB Output is correct
42 Correct 6 ms 5200 KB Output is correct
43 Correct 6 ms 5200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1232 KB Output is correct
2 Correct 7 ms 5228 KB Output is correct
3 Correct 7 ms 5200 KB Output is correct
4 Correct 7 ms 5200 KB Output is correct
5 Correct 7 ms 5200 KB Output is correct
6 Correct 7 ms 5200 KB Output is correct
7 Correct 6 ms 5200 KB Output is correct
8 Correct 7 ms 5200 KB Output is correct
9 Correct 6 ms 5268 KB Output is correct
10 Correct 8 ms 5200 KB Output is correct
11 Correct 9 ms 5200 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 10 ms 5192 KB Output is correct
14 Correct 6 ms 5200 KB Output is correct
15 Correct 7 ms 5200 KB Output is correct
16 Correct 7 ms 5200 KB Output is correct
17 Correct 9 ms 5316 KB Output is correct
18 Correct 6 ms 5272 KB Output is correct
19 Correct 8 ms 5200 KB Output is correct
20 Correct 9 ms 5192 KB Output is correct
21 Correct 8 ms 5280 KB Output is correct
22 Correct 10 ms 5200 KB Output is correct
23 Correct 9 ms 5200 KB Output is correct
24 Correct 7 ms 5200 KB Output is correct
25 Correct 4 ms 2384 KB Output is correct
26 Correct 8 ms 5300 KB Output is correct
27 Correct 7 ms 5304 KB Output is correct
28 Correct 8 ms 5328 KB Output is correct
29 Correct 9 ms 5328 KB Output is correct
30 Correct 8 ms 5316 KB Output is correct
31 Correct 8 ms 5316 KB Output is correct
32 Correct 8 ms 5248 KB Output is correct
33 Correct 6 ms 5252 KB Output is correct
34 Correct 7 ms 5280 KB Output is correct
35 Correct 7 ms 5200 KB Output is correct
36 Correct 486 ms 193588 KB Output is correct
37 Incorrect 544 ms 303844 KB 1st lines differ - on the 1st token, expected: '2946', found: '2945'
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 803 ms 175996 KB 807th lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -