#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
int seg[150000];
vector<int> h;
void build(int l, int r, int k)
{
if (l == r)
{
seg[k] = h[l];
}
build(l, (l + r) / 2, k * 2);
build((l + r) / 2 + 1, r, k * 2 + 1);
seg[k] = max(seg[k * 2], seg[k * 2 + 1]);
}
int search(int l, int r, int i, int j, int k)
{
if (l > j || r < i)
{
return 0;
}
if (i <= l && r <= j)
{
return seg[k];
}
return max(search(l, (l + r) / 2, i, j, k * 2), search((l + r) / 2 + 1, r, i, j, k * 2 + 1));
}
void init(int N, std::vector<int> H) {
h = H;
build(0, N - 1, 1);
}
int max_towers(int L, int R, int D) {
if (L == R)
{
return 1;
}
int height = 0, ans = 0;
bool used = false;
for (int i = L; i <= R; i++)
{
if (h[i] > height)
{
used = false;
height = h[i];
for (int j = i + 1; j <= R; j++)
{
int x = search(0, R, i + 1, j - 1, 1);
if ((x - h[i] >= D) && (x - h[j] >= D))
{
if (!used)
{
ans++;
used = true;
}
ans++;
}
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
1812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
2720 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
976 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
1812 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |