#include "towers.h"
#include "bits/stdc++.h"
using namespace std;
struct segtree {
vector<int> tree;
int size;
void init(int n) {
size = 1;
while (size < n) size *= 2;
tree.assign(2 * size, 0);
}
void upd(int i, int v) {
i += size;
tree[i] = max(tree[i], v);
for (; i > 1; i >>= 1) tree[i >> 1] = max(tree[i], tree[i ^ 1]);
}
int get(int l, int r) {
if (l > r) return 0;
int res = 0;
for (l += size, r += size + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1) res = max(res, tree[l++]);
if (r & 1) res = max(res, tree[--r]);
}
return res;
}
};
int n;
vector<int> a;
segtree sg1, sg2;
void init(int _n, std::vector<int> _a) {
n = _n;
a = _a;
}
int max_towers(int l, int r, int d) {
vector<int> all, v;
for (int i = 0; i < n; i++) {
all.emplace_back(a[i]);
all.emplace_back(a[i] - d);
all.emplace_back(a[i] + d);
}
sort(all.begin(), all.end());
for (int i = 0; i < all.size(); i++) {
if (i > 0 and all[i] == all[i - 1]) continue;
v.emplace_back(all[i]);
}
int z = all.size();
sg1.init(z + 1); sg2.init(z + 1);
int ans = 0;
for (int i = l; i <= r; i++) {
int pos = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
int pos2 = lower_bound(v.begin(), v.end(), a[i] + d) - v.begin();
ans = max(ans, sg1.get(pos2, z) + 1);
sg2.upd(pos2, sg1.get(pos2, z) + 1);
sg1.upd(pos, sg2.get(0, pos));
}
return ans;
}
Compilation message
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 0; i < all.size(); i++) {
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4034 ms |
7472 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
660 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
856 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
2 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
660 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
856 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
2 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
2 ms |
600 KB |
Output is correct |
36 |
Correct |
33 ms |
6612 KB |
Output is correct |
37 |
Correct |
55 ms |
11876 KB |
Output is correct |
38 |
Correct |
43 ms |
11756 KB |
Output is correct |
39 |
Correct |
52 ms |
11848 KB |
Output is correct |
40 |
Correct |
49 ms |
11696 KB |
Output is correct |
41 |
Correct |
87 ms |
11908 KB |
Output is correct |
42 |
Correct |
34 ms |
11820 KB |
Output is correct |
43 |
Correct |
41 ms |
11844 KB |
Output is correct |
44 |
Correct |
31 ms |
11844 KB |
Output is correct |
45 |
Correct |
35 ms |
11748 KB |
Output is correct |
46 |
Correct |
32 ms |
11852 KB |
Output is correct |
47 |
Correct |
60 ms |
11840 KB |
Output is correct |
48 |
Correct |
50 ms |
11844 KB |
Output is correct |
49 |
Correct |
43 ms |
11852 KB |
Output is correct |
50 |
Correct |
28 ms |
11744 KB |
Output is correct |
51 |
Correct |
32 ms |
11852 KB |
Output is correct |
52 |
Correct |
88 ms |
11912 KB |
Output is correct |
53 |
Correct |
90 ms |
11840 KB |
Output is correct |
54 |
Correct |
86 ms |
11744 KB |
Output is correct |
55 |
Correct |
53 ms |
11852 KB |
Output is correct |
56 |
Correct |
47 ms |
11860 KB |
Output is correct |
57 |
Correct |
88 ms |
11600 KB |
Output is correct |
58 |
Correct |
88 ms |
11760 KB |
Output is correct |
59 |
Correct |
94 ms |
11848 KB |
Output is correct |
60 |
Correct |
94 ms |
11844 KB |
Output is correct |
61 |
Correct |
89 ms |
11908 KB |
Output is correct |
62 |
Correct |
95 ms |
11752 KB |
Output is correct |
63 |
Correct |
98 ms |
11740 KB |
Output is correct |
64 |
Correct |
57 ms |
11844 KB |
Output is correct |
65 |
Correct |
54 ms |
11844 KB |
Output is correct |
66 |
Correct |
65 ms |
11736 KB |
Output is correct |
67 |
Correct |
62 ms |
11912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4034 ms |
13960 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4032 ms |
3780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
2 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
660 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
856 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
2 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
2 ms |
600 KB |
Output is correct |
36 |
Correct |
33 ms |
6612 KB |
Output is correct |
37 |
Correct |
55 ms |
11876 KB |
Output is correct |
38 |
Correct |
43 ms |
11756 KB |
Output is correct |
39 |
Correct |
52 ms |
11848 KB |
Output is correct |
40 |
Correct |
49 ms |
11696 KB |
Output is correct |
41 |
Correct |
87 ms |
11908 KB |
Output is correct |
42 |
Correct |
34 ms |
11820 KB |
Output is correct |
43 |
Correct |
41 ms |
11844 KB |
Output is correct |
44 |
Correct |
31 ms |
11844 KB |
Output is correct |
45 |
Correct |
35 ms |
11748 KB |
Output is correct |
46 |
Correct |
32 ms |
11852 KB |
Output is correct |
47 |
Correct |
60 ms |
11840 KB |
Output is correct |
48 |
Correct |
50 ms |
11844 KB |
Output is correct |
49 |
Correct |
43 ms |
11852 KB |
Output is correct |
50 |
Correct |
28 ms |
11744 KB |
Output is correct |
51 |
Correct |
32 ms |
11852 KB |
Output is correct |
52 |
Correct |
88 ms |
11912 KB |
Output is correct |
53 |
Correct |
90 ms |
11840 KB |
Output is correct |
54 |
Correct |
86 ms |
11744 KB |
Output is correct |
55 |
Correct |
53 ms |
11852 KB |
Output is correct |
56 |
Correct |
47 ms |
11860 KB |
Output is correct |
57 |
Correct |
88 ms |
11600 KB |
Output is correct |
58 |
Correct |
88 ms |
11760 KB |
Output is correct |
59 |
Correct |
94 ms |
11848 KB |
Output is correct |
60 |
Correct |
94 ms |
11844 KB |
Output is correct |
61 |
Correct |
89 ms |
11908 KB |
Output is correct |
62 |
Correct |
95 ms |
11752 KB |
Output is correct |
63 |
Correct |
98 ms |
11740 KB |
Output is correct |
64 |
Correct |
57 ms |
11844 KB |
Output is correct |
65 |
Correct |
54 ms |
11844 KB |
Output is correct |
66 |
Correct |
65 ms |
11736 KB |
Output is correct |
67 |
Correct |
62 ms |
11912 KB |
Output is correct |
68 |
Execution timed out |
4034 ms |
13960 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4034 ms |
7472 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |