#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
const int LOG = 18;
int n;
vector<int> h;
vector<int> spa[LOG];
int get_max(int l, int r) {
int lg = 31 - __builtin_clz(r - l + 1);
return max(spa[lg][l], spa[lg][r - (1 << lg) + 1]);
}
void init(int N_, vector<int> H_) {
n = N_, h = H_;
spa[0] = h;
for (int j = 1; (1 << j) <= n && j < LOG; ++j) {
spa[j].resize(n - (1 << j) + 1);
for (int i = 0; i + (1 << j) <= n; ++i) {
spa[j][i] = max(spa[j - 1][i], spa[j - 1][i + (1 << (j - 1))]);
}
}
}
int max_towers(int l, int r, int d) {
vector<int> ord;
for (int i = l; i <= r; ++i) {
ord.push_back(i);
}
sort(ord.begin(), ord.end(), [&](int i, int j) {
return h[i] < h[j];
});
set<int> se;
for (int i : ord) {
auto it = se.lower_bound(i);
bool ok = true;
if (it != se.end()) {
int nxt = *it;
if (nxt == i + 1 || get_max(i + 1, nxt - 1) < h[i] + d) {
ok = false;
}
}
if (it != se.begin()) {
int pre = *prev(it);
if (pre == i - 1 || get_max(pre + 1, i - 1) < h[i] + d) {
ok = false;
}
}
if (ok) {
se.insert(i);
}
}
return (int) se.size();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4059 ms |
5064 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 |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 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 |
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 |
0 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 |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
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 |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 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 |
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 |
0 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 |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
12 ms |
4952 KB |
Output is correct |
37 |
Correct |
19 ms |
7692 KB |
Output is correct |
38 |
Correct |
14 ms |
7768 KB |
Output is correct |
39 |
Correct |
15 ms |
7768 KB |
Output is correct |
40 |
Correct |
14 ms |
7664 KB |
Output is correct |
41 |
Correct |
32 ms |
8400 KB |
Output is correct |
42 |
Correct |
21 ms |
7744 KB |
Output is correct |
43 |
Correct |
13 ms |
7768 KB |
Output is correct |
44 |
Correct |
12 ms |
7596 KB |
Output is correct |
45 |
Correct |
12 ms |
7768 KB |
Output is correct |
46 |
Correct |
11 ms |
7596 KB |
Output is correct |
47 |
Correct |
20 ms |
7888 KB |
Output is correct |
48 |
Correct |
16 ms |
7888 KB |
Output is correct |
49 |
Correct |
13 ms |
7768 KB |
Output is correct |
50 |
Correct |
12 ms |
7732 KB |
Output is correct |
51 |
Correct |
12 ms |
7768 KB |
Output is correct |
52 |
Correct |
40 ms |
9300 KB |
Output is correct |
53 |
Correct |
42 ms |
9928 KB |
Output is correct |
54 |
Correct |
43 ms |
10080 KB |
Output is correct |
55 |
Correct |
13 ms |
8144 KB |
Output is correct |
56 |
Correct |
21 ms |
8056 KB |
Output is correct |
57 |
Correct |
32 ms |
7900 KB |
Output is correct |
58 |
Correct |
40 ms |
8656 KB |
Output is correct |
59 |
Correct |
38 ms |
8784 KB |
Output is correct |
60 |
Correct |
42 ms |
9936 KB |
Output is correct |
61 |
Correct |
49 ms |
9732 KB |
Output is correct |
62 |
Correct |
39 ms |
8940 KB |
Output is correct |
63 |
Correct |
48 ms |
9672 KB |
Output is correct |
64 |
Correct |
16 ms |
8144 KB |
Output is correct |
65 |
Correct |
13 ms |
8144 KB |
Output is correct |
66 |
Correct |
14 ms |
8144 KB |
Output is correct |
67 |
Correct |
13 ms |
8120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4093 ms |
9224 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4018 ms |
2444 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 |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 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 |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
0 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 |
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 |
0 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 |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
12 ms |
4952 KB |
Output is correct |
37 |
Correct |
19 ms |
7692 KB |
Output is correct |
38 |
Correct |
14 ms |
7768 KB |
Output is correct |
39 |
Correct |
15 ms |
7768 KB |
Output is correct |
40 |
Correct |
14 ms |
7664 KB |
Output is correct |
41 |
Correct |
32 ms |
8400 KB |
Output is correct |
42 |
Correct |
21 ms |
7744 KB |
Output is correct |
43 |
Correct |
13 ms |
7768 KB |
Output is correct |
44 |
Correct |
12 ms |
7596 KB |
Output is correct |
45 |
Correct |
12 ms |
7768 KB |
Output is correct |
46 |
Correct |
11 ms |
7596 KB |
Output is correct |
47 |
Correct |
20 ms |
7888 KB |
Output is correct |
48 |
Correct |
16 ms |
7888 KB |
Output is correct |
49 |
Correct |
13 ms |
7768 KB |
Output is correct |
50 |
Correct |
12 ms |
7732 KB |
Output is correct |
51 |
Correct |
12 ms |
7768 KB |
Output is correct |
52 |
Correct |
40 ms |
9300 KB |
Output is correct |
53 |
Correct |
42 ms |
9928 KB |
Output is correct |
54 |
Correct |
43 ms |
10080 KB |
Output is correct |
55 |
Correct |
13 ms |
8144 KB |
Output is correct |
56 |
Correct |
21 ms |
8056 KB |
Output is correct |
57 |
Correct |
32 ms |
7900 KB |
Output is correct |
58 |
Correct |
40 ms |
8656 KB |
Output is correct |
59 |
Correct |
38 ms |
8784 KB |
Output is correct |
60 |
Correct |
42 ms |
9936 KB |
Output is correct |
61 |
Correct |
49 ms |
9732 KB |
Output is correct |
62 |
Correct |
39 ms |
8940 KB |
Output is correct |
63 |
Correct |
48 ms |
9672 KB |
Output is correct |
64 |
Correct |
16 ms |
8144 KB |
Output is correct |
65 |
Correct |
13 ms |
8144 KB |
Output is correct |
66 |
Correct |
14 ms |
8144 KB |
Output is correct |
67 |
Correct |
13 ms |
8120 KB |
Output is correct |
68 |
Execution timed out |
4093 ms |
9224 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4059 ms |
5064 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |