답안 #833236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833236 2023-08-22T03:30:07 Z pavement 송신탑 (IOI22_towers) C++17
56 / 100
967 ms 20624 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;

#define eb emplace_back
#define mp make_pair

using ii = pair<int, int>;

int N;
bool is_init;
vector<int> H, cl, cr;
vector<vector<int> > anc;
vector<ii> segs;

void init(int N, vector<int> H) {
	::N = N;
	::H = H;
	cl = vector<int>(N, -1);
	cr = vector<int>(N, N);
	anc = vector<vector<int> >(20, vector<int>(N, -1));
}

struct node {
	node *left, *right;
	int S, E;
	ii val;
	node(int _s, int _e) : S(_s), E(_e), val(-1, -1) {
		if (S == E) {
			return;
		}
		int M = (S + E) / 2;
		left = new node(S, M);
		right = new node(M + 1, E);
	}
	void upd(int p, ii v) {
		val = max(val, v);
		if (S == E) {
			return;
		}
		int M = (S + E) / 2;
		if (p <= M) {
			left->upd(p, v);
		} else {
			right->upd(p, v);
		}
	}
	ii qry(int r) {
		if (r < S) {
			return mp(-1, -1);
		}
		if (E <= r) {
			return val;
		}
		return max(left->qry(r), right->qry(r));
	}
} *root;

int max_towers(int L, int R, int D) {
	if (!is_init) {
		vector<ii> vec;
		for (int i = 0; i < N; i++) {
			{
				int lo = 0, hi = (int)vec.size() - 1;
				while (lo <= hi) {
					int mid = (lo + hi) / 2;
					if (vec[mid].first <= H[i] - D) {
						cl[i] = vec[mid].second;
						lo = mid + 1;
					} else {
						hi = mid - 1;
					}
				}
			}
			while (!vec.empty() && vec.back().first >= H[i]) {
				vec.pop_back();
			}
			vec.eb(H[i], i);
		}
		vec.clear();
		for (int i = N - 1; i >= 0; i--) {
			{
				int lo = 0, hi = (int)vec.size() - 1;
				while (lo <= hi) {
					int mid = (lo + hi) / 2;
					if (vec[mid].first <= H[i] - D) {
						cr[i] = vec[mid].second;
						lo = mid + 1;
					} else {
						hi = mid - 1;
					}
				}
			}
			while (!vec.empty() && vec.back().first >= H[i]) {
				vec.pop_back();
			}
			vec.eb(H[i], i);
		}
		for (int i = 0; i < N; i++) {
			if (cl[i] != -1 && cr[i] != N) {
				segs.eb(cr[i], cl[i]);
			}
		}
		sort(segs.begin(), segs.end());
		root = new node(0, N - 1);
		for (int i = 0; i < (int)segs.size(); i++) {
			int to = root->qry(segs[i].second).second;
			anc[0][i] = to;
			for (int k = 1; k < 20; k++) {
				if (anc[k - 1][i] == -1) {
					break;
				}
				anc[k][i] = anc[k - 1][anc[k - 1][i]];
			}
			root->upd(segs[i].first, mp(segs[i].second, i));
		}
		is_init = 1;
	}
	int st = root->qry(R).second;
	if (st == -1 || segs[st].second < L) {
		return 1;
	}
	int ans = 2;
	for (int k = 19; k >= 0; k--) {
		if (anc[k][st] != -1 && segs[anc[k][st]].second >= L) {
			st = anc[k][st];
			ans += (1 << k);
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 217 ms 12404 KB 31st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 1 ms 592 KB Output is correct
22 Correct 1 ms 592 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 0 ms 464 KB Output is correct
26 Correct 1 ms 592 KB Output is correct
27 Correct 1 ms 592 KB Output is correct
28 Correct 1 ms 592 KB Output is correct
29 Correct 1 ms 592 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 640 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 1 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 1 ms 592 KB Output is correct
22 Correct 1 ms 592 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 0 ms 464 KB Output is correct
26 Correct 1 ms 592 KB Output is correct
27 Correct 1 ms 592 KB Output is correct
28 Correct 1 ms 592 KB Output is correct
29 Correct 1 ms 592 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 640 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 1 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
36 Correct 27 ms 12992 KB Output is correct
37 Correct 33 ms 19188 KB Output is correct
38 Correct 38 ms 19636 KB Output is correct
39 Correct 24 ms 19148 KB Output is correct
40 Correct 40 ms 19676 KB Output is correct
41 Correct 32 ms 19392 KB Output is correct
42 Correct 44 ms 19892 KB Output is correct
43 Correct 24 ms 19872 KB Output is correct
44 Correct 24 ms 19900 KB Output is correct
45 Correct 22 ms 19520 KB Output is correct
46 Correct 26 ms 19648 KB Output is correct
47 Correct 44 ms 19900 KB Output is correct
48 Correct 44 ms 19900 KB Output is correct
49 Correct 43 ms 19896 KB Output is correct
50 Correct 22 ms 19860 KB Output is correct
51 Correct 22 ms 19848 KB Output is correct
52 Correct 46 ms 19868 KB Output is correct
53 Correct 51 ms 19892 KB Output is correct
54 Correct 44 ms 19900 KB Output is correct
55 Correct 21 ms 19900 KB Output is correct
56 Correct 37 ms 19904 KB Output is correct
57 Correct 36 ms 18768 KB Output is correct
58 Correct 41 ms 19552 KB Output is correct
59 Correct 41 ms 19704 KB Output is correct
60 Correct 49 ms 19872 KB Output is correct
61 Correct 39 ms 19608 KB Output is correct
62 Correct 45 ms 19520 KB Output is correct
63 Correct 39 ms 19616 KB Output is correct
64 Correct 22 ms 19900 KB Output is correct
65 Correct 22 ms 19892 KB Output is correct
66 Correct 27 ms 19776 KB Output is correct
67 Correct 22 ms 19832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 556 ms 19652 KB Output is correct
2 Correct 723 ms 19900 KB Output is correct
3 Correct 709 ms 19988 KB Output is correct
4 Correct 777 ms 20024 KB Output is correct
5 Correct 762 ms 19900 KB Output is correct
6 Correct 779 ms 19876 KB Output is correct
7 Correct 789 ms 19900 KB Output is correct
8 Correct 713 ms 19900 KB Output is correct
9 Correct 733 ms 19900 KB Output is correct
10 Correct 740 ms 19900 KB Output is correct
11 Correct 822 ms 20028 KB Output is correct
12 Correct 705 ms 20624 KB Output is correct
13 Correct 823 ms 19768 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 50 ms 19840 KB Output is correct
18 Correct 49 ms 19812 KB Output is correct
19 Correct 43 ms 19892 KB Output is correct
20 Correct 23 ms 19900 KB Output is correct
21 Correct 22 ms 19868 KB Output is correct
22 Correct 45 ms 19896 KB Output is correct
23 Correct 49 ms 19900 KB Output is correct
24 Correct 43 ms 19920 KB Output is correct
25 Correct 22 ms 19904 KB Output is correct
26 Correct 30 ms 19904 KB Output is correct
27 Correct 1 ms 592 KB Output is correct
28 Correct 1 ms 592 KB Output is correct
29 Correct 1 ms 592 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 592 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 1 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
36 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 221 ms 4940 KB 2nd lines differ - on the 1st token, expected: '7063', found: '7197'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 1 ms 592 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 592 KB Output is correct
21 Correct 1 ms 592 KB Output is correct
22 Correct 1 ms 592 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 0 ms 464 KB Output is correct
26 Correct 1 ms 592 KB Output is correct
27 Correct 1 ms 592 KB Output is correct
28 Correct 1 ms 592 KB Output is correct
29 Correct 1 ms 592 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 640 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 1 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
36 Correct 27 ms 12992 KB Output is correct
37 Correct 33 ms 19188 KB Output is correct
38 Correct 38 ms 19636 KB Output is correct
39 Correct 24 ms 19148 KB Output is correct
40 Correct 40 ms 19676 KB Output is correct
41 Correct 32 ms 19392 KB Output is correct
42 Correct 44 ms 19892 KB Output is correct
43 Correct 24 ms 19872 KB Output is correct
44 Correct 24 ms 19900 KB Output is correct
45 Correct 22 ms 19520 KB Output is correct
46 Correct 26 ms 19648 KB Output is correct
47 Correct 44 ms 19900 KB Output is correct
48 Correct 44 ms 19900 KB Output is correct
49 Correct 43 ms 19896 KB Output is correct
50 Correct 22 ms 19860 KB Output is correct
51 Correct 22 ms 19848 KB Output is correct
52 Correct 46 ms 19868 KB Output is correct
53 Correct 51 ms 19892 KB Output is correct
54 Correct 44 ms 19900 KB Output is correct
55 Correct 21 ms 19900 KB Output is correct
56 Correct 37 ms 19904 KB Output is correct
57 Correct 36 ms 18768 KB Output is correct
58 Correct 41 ms 19552 KB Output is correct
59 Correct 41 ms 19704 KB Output is correct
60 Correct 49 ms 19872 KB Output is correct
61 Correct 39 ms 19608 KB Output is correct
62 Correct 45 ms 19520 KB Output is correct
63 Correct 39 ms 19616 KB Output is correct
64 Correct 22 ms 19900 KB Output is correct
65 Correct 22 ms 19892 KB Output is correct
66 Correct 27 ms 19776 KB Output is correct
67 Correct 22 ms 19832 KB Output is correct
68 Correct 556 ms 19652 KB Output is correct
69 Correct 723 ms 19900 KB Output is correct
70 Correct 709 ms 19988 KB Output is correct
71 Correct 777 ms 20024 KB Output is correct
72 Correct 762 ms 19900 KB Output is correct
73 Correct 779 ms 19876 KB Output is correct
74 Correct 789 ms 19900 KB Output is correct
75 Correct 713 ms 19900 KB Output is correct
76 Correct 733 ms 19900 KB Output is correct
77 Correct 740 ms 19900 KB Output is correct
78 Correct 822 ms 20028 KB Output is correct
79 Correct 705 ms 20624 KB Output is correct
80 Correct 823 ms 19768 KB Output is correct
81 Correct 0 ms 208 KB Output is correct
82 Correct 1 ms 592 KB Output is correct
83 Correct 1 ms 592 KB Output is correct
84 Correct 50 ms 19840 KB Output is correct
85 Correct 49 ms 19812 KB Output is correct
86 Correct 43 ms 19892 KB Output is correct
87 Correct 23 ms 19900 KB Output is correct
88 Correct 22 ms 19868 KB Output is correct
89 Correct 45 ms 19896 KB Output is correct
90 Correct 49 ms 19900 KB Output is correct
91 Correct 43 ms 19920 KB Output is correct
92 Correct 22 ms 19904 KB Output is correct
93 Correct 30 ms 19904 KB Output is correct
94 Correct 1 ms 592 KB Output is correct
95 Correct 1 ms 592 KB Output is correct
96 Correct 1 ms 592 KB Output is correct
97 Correct 1 ms 592 KB Output is correct
98 Correct 1 ms 592 KB Output is correct
99 Correct 1 ms 592 KB Output is correct
100 Correct 1 ms 592 KB Output is correct
101 Correct 1 ms 592 KB Output is correct
102 Correct 1 ms 592 KB Output is correct
103 Correct 1 ms 592 KB Output is correct
104 Correct 783 ms 17616 KB Output is correct
105 Correct 967 ms 19684 KB Output is correct
106 Correct 814 ms 19384 KB Output is correct
107 Correct 797 ms 19520 KB Output is correct
108 Correct 682 ms 19136 KB Output is correct
109 Correct 941 ms 19568 KB Output is correct
110 Correct 711 ms 19836 KB Output is correct
111 Correct 658 ms 19900 KB Output is correct
112 Correct 666 ms 19892 KB Output is correct
113 Correct 771 ms 19776 KB Output is correct
114 Correct 738 ms 20028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 217 ms 12404 KB 31st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -