#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
struct SegTree {
int n;
vector<int> seg;
void init (int n_) {
n = n_;
seg.resize(n * 2 - 1);
build();
}
void build(int nd, int l, int r) {
seg[nd] = 0;
if (l == r) return;
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
build(nd + 1, l, mid);
build(rs, mid + 1, r);
}
void build() {
build(0, 0, n - 1);
}
void upd (int nd, int l, int r, int p, int v) {
if (l == r) {
seg[nd] = v;
return;
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
if (p <= mid) {
upd(nd + 1, l, mid, p, v);
} else {
upd(rs, mid + 1, r, p, v);
}
seg[nd] = max(seg[nd + 1], seg[rs]);
}
void upd(int p, int v) {
upd(0, 0, n - 1, p, v);
}
int qry (int nd, int l, int r, int s, int e) {
if (l >= s && r <= e) return seg[nd];
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
if (mid >= e) {
return qry(nd + 1, l, mid, s, e);
} else {
if (mid < s) {
return qry(rs, mid + 1, r, s, e);
} else {
return max(qry(nd + 1, l, mid, s, e), qry(rs, mid + 1, r, s, e));
}
}
}
int qry(int s, int e) {
return qry(0, 0, n - 1, s, e);
}
};
vector<int> a;
vector<int> b;
SegTree not_matched;
SegTree not_complete;
void init(int N, std::vector<int> H) {
a = b = H;
sort(b.begin(), b.end());
not_matched.init(N);
not_complete.init(N);
}
int get_ind(int value) {
return upper_bound(b.begin(), b.end(), value) - b.begin() - 1;
}
int get_ind2(int value) {
return lower_bound(b.begin(), b.end(), value) - b.begin();
}
int max_towers(int L, int R, int D) {
not_complete.build();
not_matched.build();
for (int i = L; i <= R; ++i) {
int match = get_ind(a[i] - D);
if (match >= 0) {
assert(match < (int) a.size());
int best = not_matched.qry(0, match);
not_complete.upd(get_ind(a[i]), best);
}
int complete = get_ind2(a[i] + D);
int best = 0;
if (complete < (int) a.size()) {
best = not_complete.qry(complete, (int) a.size() - 1);
}
not_matched.upd(get_ind(a[i]), best + 1);
}
return not_matched.seg[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4046 ms |
2128 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
208 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
368 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
208 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
368 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
27 ms |
2344 KB |
Output is correct |
37 |
Correct |
34 ms |
3348 KB |
Output is correct |
38 |
Correct |
24 ms |
3376 KB |
Output is correct |
39 |
Correct |
25 ms |
3352 KB |
Output is correct |
40 |
Correct |
25 ms |
3376 KB |
Output is correct |
41 |
Correct |
60 ms |
3352 KB |
Output is correct |
42 |
Correct |
18 ms |
3400 KB |
Output is correct |
43 |
Correct |
30 ms |
3360 KB |
Output is correct |
44 |
Correct |
16 ms |
3372 KB |
Output is correct |
45 |
Correct |
11 ms |
3404 KB |
Output is correct |
46 |
Correct |
11 ms |
3352 KB |
Output is correct |
47 |
Correct |
43 ms |
3352 KB |
Output is correct |
48 |
Correct |
37 ms |
3400 KB |
Output is correct |
49 |
Correct |
22 ms |
3388 KB |
Output is correct |
50 |
Correct |
20 ms |
3356 KB |
Output is correct |
51 |
Correct |
27 ms |
3364 KB |
Output is correct |
52 |
Correct |
91 ms |
3376 KB |
Output is correct |
53 |
Correct |
106 ms |
3352 KB |
Output is correct |
54 |
Correct |
97 ms |
3356 KB |
Output is correct |
55 |
Correct |
52 ms |
3356 KB |
Output is correct |
56 |
Correct |
56 ms |
3400 KB |
Output is correct |
57 |
Correct |
64 ms |
3228 KB |
Output is correct |
58 |
Correct |
72 ms |
3360 KB |
Output is correct |
59 |
Correct |
82 ms |
3356 KB |
Output is correct |
60 |
Correct |
101 ms |
3368 KB |
Output is correct |
61 |
Correct |
83 ms |
3408 KB |
Output is correct |
62 |
Correct |
74 ms |
3340 KB |
Output is correct |
63 |
Correct |
85 ms |
3356 KB |
Output is correct |
64 |
Correct |
37 ms |
3360 KB |
Output is correct |
65 |
Correct |
36 ms |
3352 KB |
Output is correct |
66 |
Correct |
48 ms |
3400 KB |
Output is correct |
67 |
Correct |
43 ms |
3352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4024 ms |
3272 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4054 ms |
976 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
2 ms |
336 KB |
Output is correct |
21 |
Correct |
2 ms |
336 KB |
Output is correct |
22 |
Correct |
2 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
208 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
368 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
27 ms |
2344 KB |
Output is correct |
37 |
Correct |
34 ms |
3348 KB |
Output is correct |
38 |
Correct |
24 ms |
3376 KB |
Output is correct |
39 |
Correct |
25 ms |
3352 KB |
Output is correct |
40 |
Correct |
25 ms |
3376 KB |
Output is correct |
41 |
Correct |
60 ms |
3352 KB |
Output is correct |
42 |
Correct |
18 ms |
3400 KB |
Output is correct |
43 |
Correct |
30 ms |
3360 KB |
Output is correct |
44 |
Correct |
16 ms |
3372 KB |
Output is correct |
45 |
Correct |
11 ms |
3404 KB |
Output is correct |
46 |
Correct |
11 ms |
3352 KB |
Output is correct |
47 |
Correct |
43 ms |
3352 KB |
Output is correct |
48 |
Correct |
37 ms |
3400 KB |
Output is correct |
49 |
Correct |
22 ms |
3388 KB |
Output is correct |
50 |
Correct |
20 ms |
3356 KB |
Output is correct |
51 |
Correct |
27 ms |
3364 KB |
Output is correct |
52 |
Correct |
91 ms |
3376 KB |
Output is correct |
53 |
Correct |
106 ms |
3352 KB |
Output is correct |
54 |
Correct |
97 ms |
3356 KB |
Output is correct |
55 |
Correct |
52 ms |
3356 KB |
Output is correct |
56 |
Correct |
56 ms |
3400 KB |
Output is correct |
57 |
Correct |
64 ms |
3228 KB |
Output is correct |
58 |
Correct |
72 ms |
3360 KB |
Output is correct |
59 |
Correct |
82 ms |
3356 KB |
Output is correct |
60 |
Correct |
101 ms |
3368 KB |
Output is correct |
61 |
Correct |
83 ms |
3408 KB |
Output is correct |
62 |
Correct |
74 ms |
3340 KB |
Output is correct |
63 |
Correct |
85 ms |
3356 KB |
Output is correct |
64 |
Correct |
37 ms |
3360 KB |
Output is correct |
65 |
Correct |
36 ms |
3352 KB |
Output is correct |
66 |
Correct |
48 ms |
3400 KB |
Output is correct |
67 |
Correct |
43 ms |
3352 KB |
Output is correct |
68 |
Execution timed out |
4024 ms |
3272 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4046 ms |
2128 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |