#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
int N, p;
vector<int> H, pfs(N + 1);
void init(int n, vector<int> h) {
N = n, H = h, p = -1;
for (int i = 0; i < N; i++) {
if ((i == 0 || H[i] > H[i - 1]) && (i == N - 1 || H[i] > H[i + 1])) {
p = i;
}
}
for (int i = 0; i < p; i++) {
if (H[i] > H[i + 1]) {
p = -1;
return;
}
}
for (int i = p + 1; i < N; i++) {
if (H[i - 1] < H[i]) {
p = -1;
return;
}
}
pfs.resize(N + 1);
for (int i = 0; i < N; i++) {
pfs[i + 1] = pfs[i] + ((i == 0 || H[i] < H[i - 1]) && (i == N - 1 || H[i] < H[i + 1]));
}
}
int max_towers(int L, int R, int D) {
if (L == R) {
return 1;
}
if (p != -1) {
int l = upper_bound(H.begin(), H.begin() + p, H[p] - D) - H.begin() - 1;
int r = lower_bound(H.begin() + p, H.end(), H[p] - D, [&](int x, int y) {return x > y;}) - H.begin();
return (L <= l && r <= R) ? 2 : 1;
}
if (D == 1) {
int ans = pfs[R + 1] - pfs[L];
if (!((L == 0 || H[L] < H[L - 1]) && (L == N - 1 || H[L] < H[L + 1]))) {
if (H[L] < H[L + 1]) {
ans++;
}
}
if (!((R == 0 || H[R] < H[R - 1]) && (R == N - 1 || H[R] < H[R + 1]))) {
if (H[R] < H[R - 1]) {
ans++;
}
}
return ans;
}
vector<int> lg(N + 1);
for (int i = 2; i <= N; i++) {
lg[i] = lg[i / 2] + 1;
}
vector st(N, vector<int>(lg[N] + 1));
for (int i = 0; i < N; i++) {
st[i][0] = H[i];
}
for (int j = 0; j < lg[N]; j++) {
for (int i = 0; i + (2 << j) <= N; i++) {
st[i][j + 1] = max(st[i][j], st[i + (1 << j)][j]);
}
}
auto query = [&](int l, int r) {
if (l == r) {
return 0;
}
int k = lg[r - l];
return max(st[l][k], st[r - (1 << k)][k]);
};
vector<int> l(N, -1), r(N, N);
for (int i = 0; i < N; i++) {
if (query(0, i) >= H[i] + D) {
int lo = 0, hi = i - 1;
while (lo < hi) {
int mi = (lo + hi + 1) / 2;
if (query(mi, i) >= H[i] + D) {
lo = mi;
} else {
hi = mi - 1;
}
}
l[i] = lo;
}
if (query(i + 1, N) >= H[i] + D) {
int lo = i + 1, hi = N - 1;
while (lo < hi) {
int mi = (lo + hi) / 2;
if (query(i + 1, mi + 1) >= H[i] + D) {
hi = mi;
} else {
lo = mi + 1;
}
}
r[i] = lo;
}
}
vector<int> dp(N + 1), t(N + 1);
for (int i = L; i <= R; i++) {
t[i + 1] = max(t[i + 1], t[i]);
dp[i + 1] = max(dp[i], t[l[i] + 1] + 1);
if (r[i] < N) {
t[r[i] + 1] = max(t[r[i] + 1], dp[i + 1]);
}
}
return dp[R + 1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
376 ms |
1184 KB |
Output is correct |
2 |
Correct |
698 ms |
1832 KB |
Output is correct |
3 |
Correct |
791 ms |
1872 KB |
Output is correct |
4 |
Correct |
618 ms |
1872 KB |
Output is correct |
5 |
Correct |
672 ms |
1872 KB |
Output is correct |
6 |
Correct |
675 ms |
1828 KB |
Output is correct |
7 |
Correct |
681 ms |
1848 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 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 |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 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 |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Incorrect |
1 ms |
208 KB |
1st lines differ - on the 1st token, expected: '79', found: '1' |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 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 |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 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 |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Incorrect |
1 ms |
208 KB |
1st lines differ - on the 1st token, expected: '79', found: '1' |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
1960 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4075 ms |
3572 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 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 |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 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 |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Incorrect |
1 ms |
208 KB |
1st lines differ - on the 1st token, expected: '79', found: '1' |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
376 ms |
1184 KB |
Output is correct |
2 |
Correct |
698 ms |
1832 KB |
Output is correct |
3 |
Correct |
791 ms |
1872 KB |
Output is correct |
4 |
Correct |
618 ms |
1872 KB |
Output is correct |
5 |
Correct |
672 ms |
1872 KB |
Output is correct |
6 |
Correct |
675 ms |
1828 KB |
Output is correct |
7 |
Correct |
681 ms |
1848 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
464 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 |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
1 ms |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
0 ms |
208 KB |
Output is correct |
23 |
Correct |
1 ms |
208 KB |
Output is correct |
24 |
Correct |
1 ms |
208 KB |
Output is correct |
25 |
Incorrect |
1 ms |
208 KB |
1st lines differ - on the 1st token, expected: '79', found: '1' |
26 |
Halted |
0 ms |
0 KB |
- |