답안 #1074302

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1074302 2024-08-25T09:34:50 Z Gromp15 송신탑 (IOI22_towers) C++17
41 / 100
4000 ms 4048 KB
#include <bits/stdc++.h>
#include "towers.h"
#define ll long long
#define ar array
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
using namespace std;

template<typename T> bool ckmin(T &a, const T &b ) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b ) { return a < b ? a = b, 1 : 0; }

int n; vector<int> h, h2, pref;
int D;
int test(int i) {
	return (i && i+1 < n && ((h[i] > h[i-1] && h[i] > h[i+1])));
}
bool one_peak = 1;
int peak = -1;
void init(int N, std::vector<int> H) {
	n = N;
	h = H;
	h2 = H;
	sort(all(h2));
	h2.erase(unique(all(h2)), h2.end());
	for (int &x : h) x = lower_bound(all(h2), x) - h2.begin();
	pref.resize(n);
	for (int i = 0; i < n; i++) {
		pref[i] = test(i) + (i ? pref[i-1] : 0);
	}
	peak = max_element(all(h)) - h.begin();
	for (int i = peak-1; i >= 0; i--) one_peak &= h[i] < h[i+1];
	for (int i = peak+1; i < n; i++) one_peak &= h[i] < h[i-1];
}

struct seg {
	int N; vector<int> tree;
	seg(int n) : N(1<<(__lg(n)+1)), tree(2*N, -1e9) {}
	void update(int pos, int x) {
		for (int i = pos + N; i; i >>= 1) ckmax(tree[i], x);
	}
	int query(int node, int nl, int nr, int ql, int qr) {
		if (ql > nr || qr < nl) return -1e9;
		if (ql <= nl && nr <= qr) return tree[node];
		int mid = (nl+nr)/2;
		return max(query(node*2, nl, mid, ql, qr), query(node*2+1, mid+1, nr, ql, qr));
	}
	int query(int l, int r) {
		return query(1, 0, N-1, l, r);
	}
};

int Q = 0;
int max_towers(int L, int R, int _D) {
	D = _D;
	if (one_peak) {
		return 1 + (L < peak && R > peak && (max(h2[h[L]], h2[h[R]]) <= h2[h[peak]] - D));
	}
	if (Q++ == 0) {
		const int N = sz(h2);
		seg st0(N), st1(N); 
		for (int i = L; i <= R; i++) {
			auto it = lower_bound(all(h2), h2[h[i]] + D);
			if (it != h2.end()) {
				st1.update(h[i], st0.query(it - h2.begin(), N - 1) + 1);
			}
			auto it2 = upper_bound(all(h2), h2[h[i]] - D);
			if (it2 != h2.begin()) {
				it2--;
				st0.update(h[i], st1.query(0, it2 - h2.begin()));
			}
			st1.update(h[i], 1);
		}
		return st1.query(0, N-1);
	}
	if (D == 1) {
		return pref[R] - (L ? pref[L-1] : 0) + 1 - test(L) - test(R) + (L == R ? test(L) : 0);
	}
	int ans = 1;
	set<int> SL, SR;
	for (int i = L+1; i <= R-1; i++) if (h[i] > h[i-1] && h[i] > h[i+1]) {
		int l = -1, r = -1;
		for (int j = i-1; j >= L; j--) {
			if (h2[h[i]] - D >= h2[h[j]]) { 
				if (SL.count(j)) break;
				l = j;
			}
		}
		for (int j = i+1; j <= R; j++) {
			if (h2[h[i]] - D >= h2[h[j]]) { 
				if (SR.count(j)) break;
				r = j;
			}
		}
		if (~l && ~r) {
			ans++;
			SL.insert(l);
			SR.insert(r);
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 281 ms 1388 KB Output is correct
2 Correct 590 ms 2128 KB Output is correct
3 Correct 704 ms 2368 KB Output is correct
4 Correct 626 ms 2392 KB Output is correct
5 Correct 580 ms 2260 KB Output is correct
6 Correct 622 ms 2128 KB Output is correct
7 Correct 594 ms 2128 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 25 ms 2500 KB Output is correct
37 Correct 41 ms 4040 KB Output is correct
38 Correct 31 ms 4036 KB Output is correct
39 Correct 27 ms 4040 KB Output is correct
40 Correct 30 ms 4044 KB Output is correct
41 Correct 55 ms 4040 KB Output is correct
42 Correct 26 ms 3916 KB Output is correct
43 Correct 22 ms 2260 KB Output is correct
44 Correct 14 ms 2392 KB Output is correct
45 Correct 15 ms 4048 KB Output is correct
46 Correct 19 ms 4048 KB Output is correct
47 Correct 44 ms 4048 KB Output is correct
48 Correct 37 ms 4044 KB Output is correct
49 Correct 30 ms 3924 KB Output is correct
50 Correct 14 ms 2392 KB Output is correct
51 Correct 32 ms 4028 KB Output is correct
52 Correct 76 ms 4048 KB Output is correct
53 Correct 74 ms 4048 KB Output is correct
54 Correct 78 ms 3916 KB Output is correct
55 Correct 14 ms 2392 KB Output is correct
56 Correct 41 ms 4048 KB Output is correct
57 Correct 51 ms 3884 KB Output is correct
58 Correct 59 ms 4048 KB Output is correct
59 Correct 75 ms 4048 KB Output is correct
60 Correct 79 ms 4048 KB Output is correct
61 Correct 72 ms 4008 KB Output is correct
62 Correct 64 ms 4012 KB Output is correct
63 Correct 72 ms 4048 KB Output is correct
64 Correct 15 ms 2392 KB Output is correct
65 Correct 15 ms 2392 KB Output is correct
66 Correct 48 ms 3916 KB Output is correct
67 Correct 32 ms 4048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 528 ms 3788 KB Output is correct
2 Correct 693 ms 4040 KB Output is correct
3 Correct 658 ms 4040 KB Output is correct
4 Correct 647 ms 4040 KB Output is correct
5 Correct 744 ms 4048 KB Output is correct
6 Correct 672 ms 3916 KB Output is correct
7 Correct 762 ms 4048 KB Output is correct
8 Correct 630 ms 2392 KB Output is correct
9 Correct 697 ms 2392 KB Output is correct
10 Correct 636 ms 3924 KB Output is correct
11 Correct 635 ms 4032 KB Output is correct
12 Correct 608 ms 2392 KB Output is correct
13 Correct 662 ms 2392 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 47 ms 4040 KB Output is correct
18 Correct 43 ms 3912 KB Output is correct
19 Correct 32 ms 4048 KB Output is correct
20 Correct 22 ms 2392 KB Output is correct
21 Correct 34 ms 4040 KB Output is correct
22 Correct 90 ms 4012 KB Output is correct
23 Correct 85 ms 4040 KB Output is correct
24 Correct 96 ms 4048 KB Output is correct
25 Correct 23 ms 2392 KB Output is correct
26 Correct 50 ms 4048 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 2 ms 344 KB Output is correct
33 Correct 2 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4074 ms 1368 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 25 ms 2500 KB Output is correct
37 Correct 41 ms 4040 KB Output is correct
38 Correct 31 ms 4036 KB Output is correct
39 Correct 27 ms 4040 KB Output is correct
40 Correct 30 ms 4044 KB Output is correct
41 Correct 55 ms 4040 KB Output is correct
42 Correct 26 ms 3916 KB Output is correct
43 Correct 22 ms 2260 KB Output is correct
44 Correct 14 ms 2392 KB Output is correct
45 Correct 15 ms 4048 KB Output is correct
46 Correct 19 ms 4048 KB Output is correct
47 Correct 44 ms 4048 KB Output is correct
48 Correct 37 ms 4044 KB Output is correct
49 Correct 30 ms 3924 KB Output is correct
50 Correct 14 ms 2392 KB Output is correct
51 Correct 32 ms 4028 KB Output is correct
52 Correct 76 ms 4048 KB Output is correct
53 Correct 74 ms 4048 KB Output is correct
54 Correct 78 ms 3916 KB Output is correct
55 Correct 14 ms 2392 KB Output is correct
56 Correct 41 ms 4048 KB Output is correct
57 Correct 51 ms 3884 KB Output is correct
58 Correct 59 ms 4048 KB Output is correct
59 Correct 75 ms 4048 KB Output is correct
60 Correct 79 ms 4048 KB Output is correct
61 Correct 72 ms 4008 KB Output is correct
62 Correct 64 ms 4012 KB Output is correct
63 Correct 72 ms 4048 KB Output is correct
64 Correct 15 ms 2392 KB Output is correct
65 Correct 15 ms 2392 KB Output is correct
66 Correct 48 ms 3916 KB Output is correct
67 Correct 32 ms 4048 KB Output is correct
68 Correct 528 ms 3788 KB Output is correct
69 Correct 693 ms 4040 KB Output is correct
70 Correct 658 ms 4040 KB Output is correct
71 Correct 647 ms 4040 KB Output is correct
72 Correct 744 ms 4048 KB Output is correct
73 Correct 672 ms 3916 KB Output is correct
74 Correct 762 ms 4048 KB Output is correct
75 Correct 630 ms 2392 KB Output is correct
76 Correct 697 ms 2392 KB Output is correct
77 Correct 636 ms 3924 KB Output is correct
78 Correct 635 ms 4032 KB Output is correct
79 Correct 608 ms 2392 KB Output is correct
80 Correct 662 ms 2392 KB Output is correct
81 Correct 1 ms 344 KB Output is correct
82 Correct 1 ms 344 KB Output is correct
83 Correct 1 ms 344 KB Output is correct
84 Correct 47 ms 4040 KB Output is correct
85 Correct 43 ms 3912 KB Output is correct
86 Correct 32 ms 4048 KB Output is correct
87 Correct 22 ms 2392 KB Output is correct
88 Correct 34 ms 4040 KB Output is correct
89 Correct 90 ms 4012 KB Output is correct
90 Correct 85 ms 4040 KB Output is correct
91 Correct 96 ms 4048 KB Output is correct
92 Correct 23 ms 2392 KB Output is correct
93 Correct 50 ms 4048 KB Output is correct
94 Correct 1 ms 344 KB Output is correct
95 Correct 1 ms 344 KB Output is correct
96 Correct 1 ms 344 KB Output is correct
97 Correct 1 ms 344 KB Output is correct
98 Correct 1 ms 344 KB Output is correct
99 Correct 2 ms 344 KB Output is correct
100 Correct 2 ms 344 KB Output is correct
101 Correct 1 ms 344 KB Output is correct
102 Correct 1 ms 344 KB Output is correct
103 Correct 1 ms 344 KB Output is correct
104 Execution timed out 4061 ms 3836 KB Time limit exceeded
105 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 281 ms 1388 KB Output is correct
2 Correct 590 ms 2128 KB Output is correct
3 Correct 704 ms 2368 KB Output is correct
4 Correct 626 ms 2392 KB Output is correct
5 Correct 580 ms 2260 KB Output is correct
6 Correct 622 ms 2128 KB Output is correct
7 Correct 594 ms 2128 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 1 ms 344 KB Output is correct
46 Correct 25 ms 2500 KB Output is correct
47 Correct 41 ms 4040 KB Output is correct
48 Correct 31 ms 4036 KB Output is correct
49 Correct 27 ms 4040 KB Output is correct
50 Correct 30 ms 4044 KB Output is correct
51 Correct 55 ms 4040 KB Output is correct
52 Correct 26 ms 3916 KB Output is correct
53 Correct 22 ms 2260 KB Output is correct
54 Correct 14 ms 2392 KB Output is correct
55 Correct 15 ms 4048 KB Output is correct
56 Correct 19 ms 4048 KB Output is correct
57 Correct 44 ms 4048 KB Output is correct
58 Correct 37 ms 4044 KB Output is correct
59 Correct 30 ms 3924 KB Output is correct
60 Correct 14 ms 2392 KB Output is correct
61 Correct 32 ms 4028 KB Output is correct
62 Correct 76 ms 4048 KB Output is correct
63 Correct 74 ms 4048 KB Output is correct
64 Correct 78 ms 3916 KB Output is correct
65 Correct 14 ms 2392 KB Output is correct
66 Correct 41 ms 4048 KB Output is correct
67 Correct 51 ms 3884 KB Output is correct
68 Correct 59 ms 4048 KB Output is correct
69 Correct 75 ms 4048 KB Output is correct
70 Correct 79 ms 4048 KB Output is correct
71 Correct 72 ms 4008 KB Output is correct
72 Correct 64 ms 4012 KB Output is correct
73 Correct 72 ms 4048 KB Output is correct
74 Correct 15 ms 2392 KB Output is correct
75 Correct 15 ms 2392 KB Output is correct
76 Correct 48 ms 3916 KB Output is correct
77 Correct 32 ms 4048 KB Output is correct
78 Correct 528 ms 3788 KB Output is correct
79 Correct 693 ms 4040 KB Output is correct
80 Correct 658 ms 4040 KB Output is correct
81 Correct 647 ms 4040 KB Output is correct
82 Correct 744 ms 4048 KB Output is correct
83 Correct 672 ms 3916 KB Output is correct
84 Correct 762 ms 4048 KB Output is correct
85 Correct 630 ms 2392 KB Output is correct
86 Correct 697 ms 2392 KB Output is correct
87 Correct 636 ms 3924 KB Output is correct
88 Correct 635 ms 4032 KB Output is correct
89 Correct 608 ms 2392 KB Output is correct
90 Correct 662 ms 2392 KB Output is correct
91 Correct 1 ms 344 KB Output is correct
92 Correct 1 ms 344 KB Output is correct
93 Correct 1 ms 344 KB Output is correct
94 Correct 47 ms 4040 KB Output is correct
95 Correct 43 ms 3912 KB Output is correct
96 Correct 32 ms 4048 KB Output is correct
97 Correct 22 ms 2392 KB Output is correct
98 Correct 34 ms 4040 KB Output is correct
99 Correct 90 ms 4012 KB Output is correct
100 Correct 85 ms 4040 KB Output is correct
101 Correct 96 ms 4048 KB Output is correct
102 Correct 23 ms 2392 KB Output is correct
103 Correct 50 ms 4048 KB Output is correct
104 Correct 1 ms 344 KB Output is correct
105 Correct 1 ms 344 KB Output is correct
106 Correct 1 ms 344 KB Output is correct
107 Correct 1 ms 344 KB Output is correct
108 Correct 1 ms 344 KB Output is correct
109 Correct 2 ms 344 KB Output is correct
110 Correct 2 ms 344 KB Output is correct
111 Correct 1 ms 344 KB Output is correct
112 Correct 1 ms 344 KB Output is correct
113 Correct 1 ms 344 KB Output is correct
114 Execution timed out 4074 ms 1368 KB Time limit exceeded
115 Halted 0 ms 0 KB -