Submission #740494

# Submission time Handle Problem Language Result Execution time Memory
740494 2023-05-12T15:12:28 Z alex_2008 Radio Towers (IOI22_towers) C++17
41 / 100
1008 ms 13196 KB
#include "towers.h"
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <algorithm>
using namespace std;
int ind = -1;
bool ch = true;
vector <int> h;
const int N = 100100, M = 20;
int mx[N][M], Left[N], Right[N], pref[N];
void init(int n, vector<int> a) {
	ch = true;
	ind = -1;
	h = a;
	pref[0] = 0;
	for (int i = 0; i < n - 1; ++i)
	{
		if (a[i] > a[i + 1]) {
			if (ind == -1) ind = i;
		}
		else {
			if (ind != -1) ch = false;
		}
	}
	for (int i = 1; i < n - 1; i++) {
		pref[i] = pref[i - 1];
		if (a[i] < a[i + 1] && a[i] < a[i - 1]) pref[i]++;
	}
	for (int i = 0; i < n; i++) {
		mx[i][0] = a[i];
	}
	for (int j = 1; j < 20; j++) {
		for (int i = n - 1; i >= 0; i--) {
			mx[i][j] = max(mx[i][j - 1], mx[min(n, i + (1 << (j - 1)))][j - 1]);
		}
	}
}
int findmaxinrange(int L, int R) {
	int u = log2(R - L + 1);
	return max(mx[L][u], mx[R - (1 << u) + 1][u]);
}
int querynumber = 0;
int max_towers(int L, int R, int D) {
	++querynumber;
	if (ch) {
		if (R < ind || L > ind) return 1;
		if (h[ind] >= (max(h[L], h[R]) + D)) return 2;
		return 1;
	}
	if (querynumber == 1) {
		int n = (int)h.size();
		vector <pair<int, int>> v;
		set <int> ms;
		for (int i = 0; i < n; i++) {
			int l = 0, r = i - 1;
			Left[i] = -1;
			while (l <= r) {
				int mid = (l + r) / 2;
				if (findmaxinrange(mid, i - 1) >= h[i] + D) {
					Left[i] = mid;
					l = mid + 1;
				}
				else r = mid - 1;
			}
			Right[i] = n;
			l = i + 1, r = n - 1;
			while (l <= r) {
				int mid = (l + r) / 2;
				if (findmaxinrange(i + 1, mid) >= h[i] + D) {
					Right[i] = mid;
					r = mid - 1;
				}
				else l = mid + 1;
			}
			v.push_back({ h[i], i });
		}
		int ans = 0;
		sort(v.begin(), v.end());
		for (auto q : v) {
			int ind = q.second;
			if (ind > R || ind < L) continue;
			auto it = ms.lower_bound(ind);
			if (it != ms.begin()) {
				it--;
				if (*it > Left[ind]) continue;
			}
			it = ms.lower_bound(ind);
			if (it != ms.end() && *it < Right[ind]) {
				continue;
			}
			ms.insert(ind);
			++ans;
		}
		return ans;
	}
	if (L == R) {
		return 1;
	}
	int cnt = pref[R - 1] - pref[L];
	if (h[L] < h[L + 1]) ++cnt;
	if (h[R] < h[R - 1]) ++cnt;
	return cnt;
}
# Verdict Execution time Memory Grader output
1 Correct 469 ms 5840 KB Output is correct
2 Correct 863 ms 9672 KB Output is correct
3 Correct 818 ms 9668 KB Output is correct
4 Correct 937 ms 9640 KB Output is correct
5 Correct 689 ms 9648 KB Output is correct
6 Correct 847 ms 9644 KB Output is correct
7 Correct 632 ms 9640 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 3 ms 464 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 2 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 2 ms 464 KB Output is correct
11 Correct 2 ms 464 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 2 ms 464 KB Output is correct
16 Correct 2 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 2 ms 464 KB Output is correct
20 Correct 2 ms 464 KB Output is correct
21 Correct 2 ms 464 KB Output is correct
22 Correct 3 ms 520 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 464 KB Output is correct
27 Correct 2 ms 464 KB Output is correct
28 Correct 2 ms 464 KB Output is correct
29 Correct 2 ms 464 KB Output is correct
30 Correct 2 ms 464 KB Output is correct
31 Correct 2 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 2 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 3 ms 464 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 2 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 2 ms 464 KB Output is correct
11 Correct 2 ms 464 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 2 ms 464 KB Output is correct
16 Correct 2 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 2 ms 464 KB Output is correct
20 Correct 2 ms 464 KB Output is correct
21 Correct 2 ms 464 KB Output is correct
22 Correct 3 ms 520 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 464 KB Output is correct
27 Correct 2 ms 464 KB Output is correct
28 Correct 2 ms 464 KB Output is correct
29 Correct 2 ms 464 KB Output is correct
30 Correct 2 ms 464 KB Output is correct
31 Correct 2 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 2 ms 464 KB Output is correct
36 Correct 73 ms 7436 KB Output is correct
37 Correct 110 ms 11272 KB Output is correct
38 Correct 92 ms 11336 KB Output is correct
39 Correct 81 ms 11292 KB Output is correct
40 Correct 93 ms 11352 KB Output is correct
41 Correct 108 ms 11748 KB Output is correct
42 Correct 85 ms 11356 KB Output is correct
43 Correct 27 ms 9696 KB Output is correct
44 Correct 24 ms 9644 KB Output is correct
45 Correct 70 ms 11296 KB Output is correct
46 Correct 77 ms 11344 KB Output is correct
47 Correct 110 ms 11364 KB Output is correct
48 Correct 101 ms 11384 KB Output is correct
49 Correct 82 ms 11368 KB Output is correct
50 Correct 33 ms 9700 KB Output is correct
51 Correct 74 ms 11304 KB Output is correct
52 Correct 130 ms 12412 KB Output is correct
53 Correct 112 ms 13152 KB Output is correct
54 Correct 117 ms 13156 KB Output is correct
55 Correct 22 ms 9640 KB Output is correct
56 Correct 78 ms 11288 KB Output is correct
57 Correct 118 ms 11040 KB Output is correct
58 Correct 111 ms 11736 KB Output is correct
59 Correct 111 ms 11992 KB Output is correct
60 Correct 112 ms 13140 KB Output is correct
61 Correct 111 ms 12812 KB Output is correct
62 Correct 122 ms 12248 KB Output is correct
63 Correct 134 ms 12760 KB Output is correct
64 Correct 32 ms 9652 KB Output is correct
65 Correct 22 ms 9640 KB Output is correct
66 Correct 89 ms 11296 KB Output is correct
67 Correct 74 ms 11320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 699 ms 11348 KB Output is correct
2 Correct 858 ms 11548 KB Output is correct
3 Correct 908 ms 11292 KB Output is correct
4 Correct 868 ms 11864 KB Output is correct
5 Correct 1008 ms 11964 KB Output is correct
6 Correct 841 ms 11304 KB Output is correct
7 Correct 924 ms 12356 KB Output is correct
8 Correct 657 ms 9648 KB Output is correct
9 Correct 750 ms 9696 KB Output is correct
10 Correct 708 ms 11328 KB Output is correct
11 Correct 972 ms 11296 KB Output is correct
12 Correct 948 ms 9624 KB Output is correct
13 Correct 825 ms 9696 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 104 ms 11376 KB Output is correct
18 Correct 89 ms 11288 KB Output is correct
19 Correct 86 ms 11312 KB Output is correct
20 Correct 34 ms 9704 KB Output is correct
21 Correct 79 ms 11292 KB Output is correct
22 Correct 128 ms 12348 KB Output is correct
23 Correct 115 ms 13168 KB Output is correct
24 Correct 119 ms 13196 KB Output is correct
25 Correct 23 ms 9672 KB Output is correct
26 Correct 81 ms 11300 KB Output is correct
27 Correct 2 ms 464 KB Output is correct
28 Correct 2 ms 560 KB Output is correct
29 Correct 2 ms 464 KB Output is correct
30 Correct 1 ms 464 KB Output is correct
31 Correct 2 ms 464 KB Output is correct
32 Correct 2 ms 464 KB Output is correct
33 Correct 2 ms 464 KB Output is correct
34 Correct 3 ms 464 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 1 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 264 ms 3140 KB 2nd lines differ - on the 1st token, expected: '7063', found: '8004'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 3 ms 464 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 2 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 2 ms 464 KB Output is correct
11 Correct 2 ms 464 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 2 ms 464 KB Output is correct
16 Correct 2 ms 464 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 2 ms 464 KB Output is correct
20 Correct 2 ms 464 KB Output is correct
21 Correct 2 ms 464 KB Output is correct
22 Correct 3 ms 520 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 464 KB Output is correct
27 Correct 2 ms 464 KB Output is correct
28 Correct 2 ms 464 KB Output is correct
29 Correct 2 ms 464 KB Output is correct
30 Correct 2 ms 464 KB Output is correct
31 Correct 2 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 2 ms 464 KB Output is correct
36 Correct 73 ms 7436 KB Output is correct
37 Correct 110 ms 11272 KB Output is correct
38 Correct 92 ms 11336 KB Output is correct
39 Correct 81 ms 11292 KB Output is correct
40 Correct 93 ms 11352 KB Output is correct
41 Correct 108 ms 11748 KB Output is correct
42 Correct 85 ms 11356 KB Output is correct
43 Correct 27 ms 9696 KB Output is correct
44 Correct 24 ms 9644 KB Output is correct
45 Correct 70 ms 11296 KB Output is correct
46 Correct 77 ms 11344 KB Output is correct
47 Correct 110 ms 11364 KB Output is correct
48 Correct 101 ms 11384 KB Output is correct
49 Correct 82 ms 11368 KB Output is correct
50 Correct 33 ms 9700 KB Output is correct
51 Correct 74 ms 11304 KB Output is correct
52 Correct 130 ms 12412 KB Output is correct
53 Correct 112 ms 13152 KB Output is correct
54 Correct 117 ms 13156 KB Output is correct
55 Correct 22 ms 9640 KB Output is correct
56 Correct 78 ms 11288 KB Output is correct
57 Correct 118 ms 11040 KB Output is correct
58 Correct 111 ms 11736 KB Output is correct
59 Correct 111 ms 11992 KB Output is correct
60 Correct 112 ms 13140 KB Output is correct
61 Correct 111 ms 12812 KB Output is correct
62 Correct 122 ms 12248 KB Output is correct
63 Correct 134 ms 12760 KB Output is correct
64 Correct 32 ms 9652 KB Output is correct
65 Correct 22 ms 9640 KB Output is correct
66 Correct 89 ms 11296 KB Output is correct
67 Correct 74 ms 11320 KB Output is correct
68 Correct 699 ms 11348 KB Output is correct
69 Correct 858 ms 11548 KB Output is correct
70 Correct 908 ms 11292 KB Output is correct
71 Correct 868 ms 11864 KB Output is correct
72 Correct 1008 ms 11964 KB Output is correct
73 Correct 841 ms 11304 KB Output is correct
74 Correct 924 ms 12356 KB Output is correct
75 Correct 657 ms 9648 KB Output is correct
76 Correct 750 ms 9696 KB Output is correct
77 Correct 708 ms 11328 KB Output is correct
78 Correct 972 ms 11296 KB Output is correct
79 Correct 948 ms 9624 KB Output is correct
80 Correct 825 ms 9696 KB Output is correct
81 Correct 0 ms 208 KB Output is correct
82 Correct 1 ms 464 KB Output is correct
83 Correct 1 ms 464 KB Output is correct
84 Correct 104 ms 11376 KB Output is correct
85 Correct 89 ms 11288 KB Output is correct
86 Correct 86 ms 11312 KB Output is correct
87 Correct 34 ms 9704 KB Output is correct
88 Correct 79 ms 11292 KB Output is correct
89 Correct 128 ms 12348 KB Output is correct
90 Correct 115 ms 13168 KB Output is correct
91 Correct 119 ms 13196 KB Output is correct
92 Correct 23 ms 9672 KB Output is correct
93 Correct 81 ms 11300 KB Output is correct
94 Correct 2 ms 464 KB Output is correct
95 Correct 2 ms 560 KB Output is correct
96 Correct 2 ms 464 KB Output is correct
97 Correct 1 ms 464 KB Output is correct
98 Correct 2 ms 464 KB Output is correct
99 Correct 2 ms 464 KB Output is correct
100 Correct 2 ms 464 KB Output is correct
101 Correct 3 ms 464 KB Output is correct
102 Correct 1 ms 464 KB Output is correct
103 Correct 1 ms 476 KB Output is correct
104 Incorrect 949 ms 10348 KB 2nd lines differ - on the 1st token, expected: '18702', found: '21427'
105 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 469 ms 5840 KB Output is correct
2 Correct 863 ms 9672 KB Output is correct
3 Correct 818 ms 9668 KB Output is correct
4 Correct 937 ms 9640 KB Output is correct
5 Correct 689 ms 9648 KB Output is correct
6 Correct 847 ms 9644 KB Output is correct
7 Correct 632 ms 9640 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 2 ms 464 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 2 ms 464 KB Output is correct
15 Correct 3 ms 464 KB Output is correct
16 Correct 2 ms 464 KB Output is correct
17 Correct 2 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 2 ms 464 KB Output is correct
21 Correct 2 ms 464 KB Output is correct
22 Correct 0 ms 208 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 2 ms 464 KB Output is correct
26 Correct 2 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 2 ms 464 KB Output is correct
30 Correct 2 ms 464 KB Output is correct
31 Correct 2 ms 464 KB Output is correct
32 Correct 3 ms 520 KB Output is correct
33 Correct 1 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 2 ms 464 KB Output is correct
37 Correct 2 ms 464 KB Output is correct
38 Correct 2 ms 464 KB Output is correct
39 Correct 2 ms 464 KB Output is correct
40 Correct 2 ms 464 KB Output is correct
41 Correct 2 ms 464 KB Output is correct
42 Correct 1 ms 464 KB Output is correct
43 Correct 1 ms 464 KB Output is correct
44 Correct 1 ms 464 KB Output is correct
45 Correct 2 ms 464 KB Output is correct
46 Correct 73 ms 7436 KB Output is correct
47 Correct 110 ms 11272 KB Output is correct
48 Correct 92 ms 11336 KB Output is correct
49 Correct 81 ms 11292 KB Output is correct
50 Correct 93 ms 11352 KB Output is correct
51 Correct 108 ms 11748 KB Output is correct
52 Correct 85 ms 11356 KB Output is correct
53 Correct 27 ms 9696 KB Output is correct
54 Correct 24 ms 9644 KB Output is correct
55 Correct 70 ms 11296 KB Output is correct
56 Correct 77 ms 11344 KB Output is correct
57 Correct 110 ms 11364 KB Output is correct
58 Correct 101 ms 11384 KB Output is correct
59 Correct 82 ms 11368 KB Output is correct
60 Correct 33 ms 9700 KB Output is correct
61 Correct 74 ms 11304 KB Output is correct
62 Correct 130 ms 12412 KB Output is correct
63 Correct 112 ms 13152 KB Output is correct
64 Correct 117 ms 13156 KB Output is correct
65 Correct 22 ms 9640 KB Output is correct
66 Correct 78 ms 11288 KB Output is correct
67 Correct 118 ms 11040 KB Output is correct
68 Correct 111 ms 11736 KB Output is correct
69 Correct 111 ms 11992 KB Output is correct
70 Correct 112 ms 13140 KB Output is correct
71 Correct 111 ms 12812 KB Output is correct
72 Correct 122 ms 12248 KB Output is correct
73 Correct 134 ms 12760 KB Output is correct
74 Correct 32 ms 9652 KB Output is correct
75 Correct 22 ms 9640 KB Output is correct
76 Correct 89 ms 11296 KB Output is correct
77 Correct 74 ms 11320 KB Output is correct
78 Correct 699 ms 11348 KB Output is correct
79 Correct 858 ms 11548 KB Output is correct
80 Correct 908 ms 11292 KB Output is correct
81 Correct 868 ms 11864 KB Output is correct
82 Correct 1008 ms 11964 KB Output is correct
83 Correct 841 ms 11304 KB Output is correct
84 Correct 924 ms 12356 KB Output is correct
85 Correct 657 ms 9648 KB Output is correct
86 Correct 750 ms 9696 KB Output is correct
87 Correct 708 ms 11328 KB Output is correct
88 Correct 972 ms 11296 KB Output is correct
89 Correct 948 ms 9624 KB Output is correct
90 Correct 825 ms 9696 KB Output is correct
91 Correct 0 ms 208 KB Output is correct
92 Correct 1 ms 464 KB Output is correct
93 Correct 1 ms 464 KB Output is correct
94 Correct 104 ms 11376 KB Output is correct
95 Correct 89 ms 11288 KB Output is correct
96 Correct 86 ms 11312 KB Output is correct
97 Correct 34 ms 9704 KB Output is correct
98 Correct 79 ms 11292 KB Output is correct
99 Correct 128 ms 12348 KB Output is correct
100 Correct 115 ms 13168 KB Output is correct
101 Correct 119 ms 13196 KB Output is correct
102 Correct 23 ms 9672 KB Output is correct
103 Correct 81 ms 11300 KB Output is correct
104 Correct 2 ms 464 KB Output is correct
105 Correct 2 ms 560 KB Output is correct
106 Correct 2 ms 464 KB Output is correct
107 Correct 1 ms 464 KB Output is correct
108 Correct 2 ms 464 KB Output is correct
109 Correct 2 ms 464 KB Output is correct
110 Correct 2 ms 464 KB Output is correct
111 Correct 3 ms 464 KB Output is correct
112 Correct 1 ms 464 KB Output is correct
113 Correct 1 ms 476 KB Output is correct
114 Incorrect 264 ms 3140 KB 2nd lines differ - on the 1st token, expected: '7063', found: '8004'
115 Halted 0 ms 0 KB -