#include "towers.h"
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
int n;
vector<int> H;
vector<pair<int, int>> byH;
const int MX_N = 1e5, LG = 17;
int rmq[1+LG][MX_N];
int p2[MX_N];
int rangeMax(int l, int r) {
int p = p2[r-l+1];
return max(rmq[p][l], rmq[p][r-(1<<p)+1]);
}
bool connected(int x, int y, int d) {
if (x == y) return true;
if (x > y) swap(x, y);
if (x+1 == y) return false;
return rangeMax(x+1, y-1) - d >= max(H[x], H[y]);
}
void init(int N, vector<int> Hs) {
for (int i = 2; i <= N; ++i) p2[i] = p2[i-1] + !(i & (i-1));
n = N, H = Hs;
for (int i = 0; i < n; ++i) byH.emplace_back(H[i], i);
sort(byH.begin(), byH.end());
// rmq
for (int i = 0; i < n; ++i) rmq[0][i] = H[i];
for (int i = 1, p = 1; i <= LG; ++i, p <<= 1) {
for (int j = 0; j < n; ++j) {
if (j+p >= n) rmq[i][j] = rmq[i-1][j];
else rmq[i][j] = max(rmq[i-1][j], rmq[i-1][j+p]);
}
}
}
int max_towers(int L, int R, int D) {
set<int> included;
for (auto [h, i] : byH) {
if (i < L || i > R) continue;
set<int>::iterator it = included.lower_bound(i);
if (it != included.end() && !connected(i, *it, D)) continue;
if (it != included.begin() && !connected(*prev(it), i, D)) continue;
included.insert(i);
}
return included.size();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4067 ms |
6036 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
464 KB |
Output is correct |
14 |
Correct |
1 ms |
464 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 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 |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
464 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 |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
0 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
464 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
512 KB |
Output is correct |
34 |
Correct |
1 ms |
464 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
464 KB |
Output is correct |
14 |
Correct |
1 ms |
464 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 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 |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
464 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 |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
0 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
464 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
512 KB |
Output is correct |
34 |
Correct |
1 ms |
464 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
36 |
Correct |
19 ms |
6724 KB |
Output is correct |
37 |
Correct |
24 ms |
9752 KB |
Output is correct |
38 |
Correct |
22 ms |
9744 KB |
Output is correct |
39 |
Correct |
25 ms |
9728 KB |
Output is correct |
40 |
Correct |
28 ms |
9788 KB |
Output is correct |
41 |
Correct |
34 ms |
10152 KB |
Output is correct |
42 |
Correct |
21 ms |
9796 KB |
Output is correct |
43 |
Correct |
17 ms |
9796 KB |
Output is correct |
44 |
Correct |
15 ms |
9796 KB |
Output is correct |
45 |
Correct |
15 ms |
9796 KB |
Output is correct |
46 |
Correct |
15 ms |
9796 KB |
Output is correct |
47 |
Correct |
27 ms |
9796 KB |
Output is correct |
48 |
Correct |
24 ms |
9796 KB |
Output is correct |
49 |
Correct |
22 ms |
9788 KB |
Output is correct |
50 |
Correct |
19 ms |
9796 KB |
Output is correct |
51 |
Correct |
21 ms |
9744 KB |
Output is correct |
52 |
Correct |
43 ms |
10732 KB |
Output is correct |
53 |
Correct |
43 ms |
11548 KB |
Output is correct |
54 |
Correct |
43 ms |
11572 KB |
Output is correct |
55 |
Correct |
16 ms |
9740 KB |
Output is correct |
56 |
Correct |
16 ms |
9796 KB |
Output is correct |
57 |
Correct |
37 ms |
9624 KB |
Output is correct |
58 |
Correct |
37 ms |
10172 KB |
Output is correct |
59 |
Correct |
38 ms |
10420 KB |
Output is correct |
60 |
Correct |
44 ms |
11572 KB |
Output is correct |
61 |
Correct |
41 ms |
11204 KB |
Output is correct |
62 |
Correct |
38 ms |
10672 KB |
Output is correct |
63 |
Correct |
42 ms |
11188 KB |
Output is correct |
64 |
Correct |
15 ms |
9796 KB |
Output is correct |
65 |
Correct |
21 ms |
9744 KB |
Output is correct |
66 |
Correct |
16 ms |
9796 KB |
Output is correct |
67 |
Correct |
21 ms |
9744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4078 ms |
10676 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4059 ms |
2896 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
0 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
464 KB |
Output is correct |
14 |
Correct |
1 ms |
464 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 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 |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
464 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 |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
0 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
464 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
512 KB |
Output is correct |
34 |
Correct |
1 ms |
464 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
36 |
Correct |
19 ms |
6724 KB |
Output is correct |
37 |
Correct |
24 ms |
9752 KB |
Output is correct |
38 |
Correct |
22 ms |
9744 KB |
Output is correct |
39 |
Correct |
25 ms |
9728 KB |
Output is correct |
40 |
Correct |
28 ms |
9788 KB |
Output is correct |
41 |
Correct |
34 ms |
10152 KB |
Output is correct |
42 |
Correct |
21 ms |
9796 KB |
Output is correct |
43 |
Correct |
17 ms |
9796 KB |
Output is correct |
44 |
Correct |
15 ms |
9796 KB |
Output is correct |
45 |
Correct |
15 ms |
9796 KB |
Output is correct |
46 |
Correct |
15 ms |
9796 KB |
Output is correct |
47 |
Correct |
27 ms |
9796 KB |
Output is correct |
48 |
Correct |
24 ms |
9796 KB |
Output is correct |
49 |
Correct |
22 ms |
9788 KB |
Output is correct |
50 |
Correct |
19 ms |
9796 KB |
Output is correct |
51 |
Correct |
21 ms |
9744 KB |
Output is correct |
52 |
Correct |
43 ms |
10732 KB |
Output is correct |
53 |
Correct |
43 ms |
11548 KB |
Output is correct |
54 |
Correct |
43 ms |
11572 KB |
Output is correct |
55 |
Correct |
16 ms |
9740 KB |
Output is correct |
56 |
Correct |
16 ms |
9796 KB |
Output is correct |
57 |
Correct |
37 ms |
9624 KB |
Output is correct |
58 |
Correct |
37 ms |
10172 KB |
Output is correct |
59 |
Correct |
38 ms |
10420 KB |
Output is correct |
60 |
Correct |
44 ms |
11572 KB |
Output is correct |
61 |
Correct |
41 ms |
11204 KB |
Output is correct |
62 |
Correct |
38 ms |
10672 KB |
Output is correct |
63 |
Correct |
42 ms |
11188 KB |
Output is correct |
64 |
Correct |
15 ms |
9796 KB |
Output is correct |
65 |
Correct |
21 ms |
9744 KB |
Output is correct |
66 |
Correct |
16 ms |
9796 KB |
Output is correct |
67 |
Correct |
21 ms |
9744 KB |
Output is correct |
68 |
Execution timed out |
4078 ms |
10676 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4067 ms |
6036 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |