#include "towers.h"
#ifdef NYAOWO
#include "stub.cpp"
#endif
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
// #define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;
inline void chmax(int &x, int val) { x = max(x, val); }
const int MAXN = 100'000;
#define L(id) ((id) * 2 + 1)
#define R(id) ((id) * 2 + 2)
struct SegTree {
int mx[MAXN * 4 + 10];
void build() {
memset(mx, 0, sizeof(mx));
}
void upd(int id, int l, int r, int pos, int val) {
if(l == r) {
chmax(mx[id], val);
return;
}
int m = (l + r) / 2;
if(pos <= m) upd(L(id), l, m, pos, val);
else upd(R(id), m + 1, r, pos, val);
mx[id] = max(mx[L(id)], mx[R(id)]);
}
int range_max(int id, int l, int r, int L, int R) {
if(L > R) return 0;
if(l >= L && r <= R) {
return mx[id];
}
int m = (l + r) / 2;
int res = 0;
if(L <= m) chmax(res, range_max(L(id), l, m, L, R));
if(R > m) chmax(res, range_max(R(id), m + 1, r, L, R));
return res;
}
} dp1, dp2;
int n;
int h[MAXN + 10];
int vals[MAXN + 10];
void init(int N, std::vector<int> H) {
n = N;
For(i, 0, n - 1) {
h[i] = H[i];
vals[i] = h[i];
}
sort(vals, vals + n);
}
int max_towers(int L, int R, int D) {
int ans = 0;
dp1.build();
dp2.build();
For(i, L, R) {
int p = (int)(lower_bound(vals, vals + n, h[i]) - vals);
int l = (int)(upper_bound(vals, vals + n, h[i] - D) - vals) - 1;
int r = (int)(lower_bound(vals, vals + n, h[i] + D) - vals);
int v1 = dp2.range_max(0, 0, n - 1, r, n - 1) + 1;
int v2 = dp1.range_max(0, 0, n - 1, 0, l);
dp1.upd(0, 0, n - 1, p, v1);
dp2.upd(0, 0, n - 1, p, v2);
chmax(ans, v1);
}
return ans;
}
/*
7 3
10 20 60 40 50 30 70
1 5 10
2 2 100
0 6 17
3
1
2
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4025 ms |
4068 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3408 KB |
Output is correct |
2 |
Correct |
2 ms |
3408 KB |
Output is correct |
3 |
Correct |
2 ms |
3408 KB |
Output is correct |
4 |
Correct |
2 ms |
3392 KB |
Output is correct |
5 |
Correct |
2 ms |
3408 KB |
Output is correct |
6 |
Correct |
2 ms |
3408 KB |
Output is correct |
7 |
Correct |
2 ms |
3408 KB |
Output is correct |
8 |
Correct |
1 ms |
3408 KB |
Output is correct |
9 |
Correct |
2 ms |
3408 KB |
Output is correct |
10 |
Correct |
2 ms |
3408 KB |
Output is correct |
11 |
Correct |
1 ms |
3408 KB |
Output is correct |
12 |
Correct |
1 ms |
3408 KB |
Output is correct |
13 |
Correct |
2 ms |
3408 KB |
Output is correct |
14 |
Correct |
2 ms |
3408 KB |
Output is correct |
15 |
Correct |
2 ms |
3408 KB |
Output is correct |
16 |
Correct |
2 ms |
3408 KB |
Output is correct |
17 |
Correct |
2 ms |
3408 KB |
Output is correct |
18 |
Correct |
2 ms |
3408 KB |
Output is correct |
19 |
Correct |
2 ms |
3384 KB |
Output is correct |
20 |
Correct |
4 ms |
3460 KB |
Output is correct |
21 |
Correct |
2 ms |
3408 KB |
Output is correct |
22 |
Correct |
3 ms |
3408 KB |
Output is correct |
23 |
Correct |
2 ms |
3408 KB |
Output is correct |
24 |
Correct |
2 ms |
3408 KB |
Output is correct |
25 |
Correct |
2 ms |
3408 KB |
Output is correct |
26 |
Correct |
2 ms |
3408 KB |
Output is correct |
27 |
Correct |
2 ms |
3408 KB |
Output is correct |
28 |
Correct |
2 ms |
3408 KB |
Output is correct |
29 |
Correct |
2 ms |
3408 KB |
Output is correct |
30 |
Correct |
2 ms |
3408 KB |
Output is correct |
31 |
Correct |
2 ms |
3444 KB |
Output is correct |
32 |
Correct |
2 ms |
3408 KB |
Output is correct |
33 |
Correct |
2 ms |
3408 KB |
Output is correct |
34 |
Correct |
2 ms |
3408 KB |
Output is correct |
35 |
Correct |
2 ms |
3408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3408 KB |
Output is correct |
2 |
Correct |
2 ms |
3408 KB |
Output is correct |
3 |
Correct |
2 ms |
3408 KB |
Output is correct |
4 |
Correct |
2 ms |
3392 KB |
Output is correct |
5 |
Correct |
2 ms |
3408 KB |
Output is correct |
6 |
Correct |
2 ms |
3408 KB |
Output is correct |
7 |
Correct |
2 ms |
3408 KB |
Output is correct |
8 |
Correct |
1 ms |
3408 KB |
Output is correct |
9 |
Correct |
2 ms |
3408 KB |
Output is correct |
10 |
Correct |
2 ms |
3408 KB |
Output is correct |
11 |
Correct |
1 ms |
3408 KB |
Output is correct |
12 |
Correct |
1 ms |
3408 KB |
Output is correct |
13 |
Correct |
2 ms |
3408 KB |
Output is correct |
14 |
Correct |
2 ms |
3408 KB |
Output is correct |
15 |
Correct |
2 ms |
3408 KB |
Output is correct |
16 |
Correct |
2 ms |
3408 KB |
Output is correct |
17 |
Correct |
2 ms |
3408 KB |
Output is correct |
18 |
Correct |
2 ms |
3408 KB |
Output is correct |
19 |
Correct |
2 ms |
3384 KB |
Output is correct |
20 |
Correct |
4 ms |
3460 KB |
Output is correct |
21 |
Correct |
2 ms |
3408 KB |
Output is correct |
22 |
Correct |
3 ms |
3408 KB |
Output is correct |
23 |
Correct |
2 ms |
3408 KB |
Output is correct |
24 |
Correct |
2 ms |
3408 KB |
Output is correct |
25 |
Correct |
2 ms |
3408 KB |
Output is correct |
26 |
Correct |
2 ms |
3408 KB |
Output is correct |
27 |
Correct |
2 ms |
3408 KB |
Output is correct |
28 |
Correct |
2 ms |
3408 KB |
Output is correct |
29 |
Correct |
2 ms |
3408 KB |
Output is correct |
30 |
Correct |
2 ms |
3408 KB |
Output is correct |
31 |
Correct |
2 ms |
3444 KB |
Output is correct |
32 |
Correct |
2 ms |
3408 KB |
Output is correct |
33 |
Correct |
2 ms |
3408 KB |
Output is correct |
34 |
Correct |
2 ms |
3408 KB |
Output is correct |
35 |
Correct |
2 ms |
3408 KB |
Output is correct |
36 |
Correct |
24 ms |
4176 KB |
Output is correct |
37 |
Correct |
39 ms |
4596 KB |
Output is correct |
38 |
Correct |
29 ms |
4544 KB |
Output is correct |
39 |
Correct |
28 ms |
4528 KB |
Output is correct |
40 |
Correct |
24 ms |
4512 KB |
Output is correct |
41 |
Correct |
69 ms |
4512 KB |
Output is correct |
42 |
Correct |
18 ms |
4572 KB |
Output is correct |
43 |
Correct |
30 ms |
4592 KB |
Output is correct |
44 |
Correct |
20 ms |
4528 KB |
Output is correct |
45 |
Correct |
12 ms |
4520 KB |
Output is correct |
46 |
Correct |
12 ms |
4524 KB |
Output is correct |
47 |
Correct |
48 ms |
4496 KB |
Output is correct |
48 |
Correct |
31 ms |
4540 KB |
Output is correct |
49 |
Correct |
28 ms |
4592 KB |
Output is correct |
50 |
Correct |
20 ms |
4592 KB |
Output is correct |
51 |
Correct |
28 ms |
4544 KB |
Output is correct |
52 |
Correct |
95 ms |
4596 KB |
Output is correct |
53 |
Correct |
92 ms |
4592 KB |
Output is correct |
54 |
Correct |
101 ms |
4544 KB |
Output is correct |
55 |
Correct |
55 ms |
4512 KB |
Output is correct |
56 |
Correct |
57 ms |
4600 KB |
Output is correct |
57 |
Correct |
69 ms |
4560 KB |
Output is correct |
58 |
Correct |
73 ms |
4512 KB |
Output is correct |
59 |
Correct |
84 ms |
4556 KB |
Output is correct |
60 |
Correct |
95 ms |
4544 KB |
Output is correct |
61 |
Correct |
86 ms |
4592 KB |
Output is correct |
62 |
Correct |
80 ms |
4592 KB |
Output is correct |
63 |
Correct |
85 ms |
4596 KB |
Output is correct |
64 |
Correct |
41 ms |
4544 KB |
Output is correct |
65 |
Correct |
39 ms |
4632 KB |
Output is correct |
66 |
Correct |
53 ms |
4596 KB |
Output is correct |
67 |
Correct |
40 ms |
4544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4006 ms |
4556 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4096 ms |
3792 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3408 KB |
Output is correct |
2 |
Correct |
2 ms |
3408 KB |
Output is correct |
3 |
Correct |
2 ms |
3408 KB |
Output is correct |
4 |
Correct |
2 ms |
3392 KB |
Output is correct |
5 |
Correct |
2 ms |
3408 KB |
Output is correct |
6 |
Correct |
2 ms |
3408 KB |
Output is correct |
7 |
Correct |
2 ms |
3408 KB |
Output is correct |
8 |
Correct |
1 ms |
3408 KB |
Output is correct |
9 |
Correct |
2 ms |
3408 KB |
Output is correct |
10 |
Correct |
2 ms |
3408 KB |
Output is correct |
11 |
Correct |
1 ms |
3408 KB |
Output is correct |
12 |
Correct |
1 ms |
3408 KB |
Output is correct |
13 |
Correct |
2 ms |
3408 KB |
Output is correct |
14 |
Correct |
2 ms |
3408 KB |
Output is correct |
15 |
Correct |
2 ms |
3408 KB |
Output is correct |
16 |
Correct |
2 ms |
3408 KB |
Output is correct |
17 |
Correct |
2 ms |
3408 KB |
Output is correct |
18 |
Correct |
2 ms |
3408 KB |
Output is correct |
19 |
Correct |
2 ms |
3384 KB |
Output is correct |
20 |
Correct |
4 ms |
3460 KB |
Output is correct |
21 |
Correct |
2 ms |
3408 KB |
Output is correct |
22 |
Correct |
3 ms |
3408 KB |
Output is correct |
23 |
Correct |
2 ms |
3408 KB |
Output is correct |
24 |
Correct |
2 ms |
3408 KB |
Output is correct |
25 |
Correct |
2 ms |
3408 KB |
Output is correct |
26 |
Correct |
2 ms |
3408 KB |
Output is correct |
27 |
Correct |
2 ms |
3408 KB |
Output is correct |
28 |
Correct |
2 ms |
3408 KB |
Output is correct |
29 |
Correct |
2 ms |
3408 KB |
Output is correct |
30 |
Correct |
2 ms |
3408 KB |
Output is correct |
31 |
Correct |
2 ms |
3444 KB |
Output is correct |
32 |
Correct |
2 ms |
3408 KB |
Output is correct |
33 |
Correct |
2 ms |
3408 KB |
Output is correct |
34 |
Correct |
2 ms |
3408 KB |
Output is correct |
35 |
Correct |
2 ms |
3408 KB |
Output is correct |
36 |
Correct |
24 ms |
4176 KB |
Output is correct |
37 |
Correct |
39 ms |
4596 KB |
Output is correct |
38 |
Correct |
29 ms |
4544 KB |
Output is correct |
39 |
Correct |
28 ms |
4528 KB |
Output is correct |
40 |
Correct |
24 ms |
4512 KB |
Output is correct |
41 |
Correct |
69 ms |
4512 KB |
Output is correct |
42 |
Correct |
18 ms |
4572 KB |
Output is correct |
43 |
Correct |
30 ms |
4592 KB |
Output is correct |
44 |
Correct |
20 ms |
4528 KB |
Output is correct |
45 |
Correct |
12 ms |
4520 KB |
Output is correct |
46 |
Correct |
12 ms |
4524 KB |
Output is correct |
47 |
Correct |
48 ms |
4496 KB |
Output is correct |
48 |
Correct |
31 ms |
4540 KB |
Output is correct |
49 |
Correct |
28 ms |
4592 KB |
Output is correct |
50 |
Correct |
20 ms |
4592 KB |
Output is correct |
51 |
Correct |
28 ms |
4544 KB |
Output is correct |
52 |
Correct |
95 ms |
4596 KB |
Output is correct |
53 |
Correct |
92 ms |
4592 KB |
Output is correct |
54 |
Correct |
101 ms |
4544 KB |
Output is correct |
55 |
Correct |
55 ms |
4512 KB |
Output is correct |
56 |
Correct |
57 ms |
4600 KB |
Output is correct |
57 |
Correct |
69 ms |
4560 KB |
Output is correct |
58 |
Correct |
73 ms |
4512 KB |
Output is correct |
59 |
Correct |
84 ms |
4556 KB |
Output is correct |
60 |
Correct |
95 ms |
4544 KB |
Output is correct |
61 |
Correct |
86 ms |
4592 KB |
Output is correct |
62 |
Correct |
80 ms |
4592 KB |
Output is correct |
63 |
Correct |
85 ms |
4596 KB |
Output is correct |
64 |
Correct |
41 ms |
4544 KB |
Output is correct |
65 |
Correct |
39 ms |
4632 KB |
Output is correct |
66 |
Correct |
53 ms |
4596 KB |
Output is correct |
67 |
Correct |
40 ms |
4544 KB |
Output is correct |
68 |
Execution timed out |
4006 ms |
4556 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4025 ms |
4068 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |