#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
struct segtree{
int k = 1;
vector<int> v;
segtree(int n){
while(k < n) k*=2;
v.assign(2*k, 0);
}
void update(int i, int x){
i+=k;
v[i] = x;
i/=2;
while(i){
v[i] = max(v[2*i], v[2*i+1]);
i/=2;
}
}
int get(int l, int r, int nd, int a, int b){
if(a > r || b < l) return 0;
if(a >= l && b <= r) return v[nd];
int md = (a+b)/2;
return max(get(l, r, 2*nd, a, md), get(l, r, 2*nd+1, md+1, b));
}
int get(int l, int r){
if(l > r) return 0;
return get(l, r, 1, 0, k-1);
}
};
int n;
vector<int> h;
segtree seg(0);
vector<int> o;
void init(int _n, vector<int> _h){
swap(n, _n);
swap(h, _h);
seg = segtree(n);
for(int i = 0; i < n; i++) seg.update(i, h[i]);
for(int i = 0; i < n; i++) o.pb(i);
sort(o.begin(), o.end(), [&](int a, int b){
return h[a] < h[b];
});
}
int max_towers(int L, int R, int D){
set<int> s;
for(int i: o){
if(i < L || i > R) continue;
auto it = s.upper_bound(i);
bool ok = 1;
if(it != s.end() && seg.get(i+1, *it-1) < h[i]+D) ok = 0;
if(it != s.begin() && seg.get(*prev(it)+1, i-1) < h[i]+D) ok = 0;
if(ok) s.insert(i);
}
return s.size();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4057 ms |
1564 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 |
336 KB |
Output is correct |
3 |
Correct |
2 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 |
2 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 |
0 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 |
2 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 |
1 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 |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
208 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 |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 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 |
2 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 |
0 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 |
2 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 |
1 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 |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
208 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 |
32 ms |
1824 KB |
Output is correct |
37 |
Correct |
47 ms |
2712 KB |
Output is correct |
38 |
Correct |
32 ms |
2768 KB |
Output is correct |
39 |
Correct |
38 ms |
2624 KB |
Output is correct |
40 |
Correct |
29 ms |
2724 KB |
Output is correct |
41 |
Correct |
74 ms |
3348 KB |
Output is correct |
42 |
Correct |
36 ms |
2720 KB |
Output is correct |
43 |
Correct |
34 ms |
2708 KB |
Output is correct |
44 |
Correct |
21 ms |
2736 KB |
Output is correct |
45 |
Correct |
26 ms |
2708 KB |
Output is correct |
46 |
Correct |
18 ms |
2836 KB |
Output is correct |
47 |
Correct |
44 ms |
3152 KB |
Output is correct |
48 |
Correct |
33 ms |
2888 KB |
Output is correct |
49 |
Correct |
36 ms |
2724 KB |
Output is correct |
50 |
Correct |
21 ms |
2736 KB |
Output is correct |
51 |
Correct |
22 ms |
2720 KB |
Output is correct |
52 |
Correct |
74 ms |
4120 KB |
Output is correct |
53 |
Correct |
75 ms |
4760 KB |
Output is correct |
54 |
Correct |
68 ms |
4920 KB |
Output is correct |
55 |
Correct |
31 ms |
2764 KB |
Output is correct |
56 |
Correct |
40 ms |
2764 KB |
Output is correct |
57 |
Correct |
70 ms |
2944 KB |
Output is correct |
58 |
Correct |
68 ms |
3368 KB |
Output is correct |
59 |
Correct |
79 ms |
3604 KB |
Output is correct |
60 |
Correct |
80 ms |
4804 KB |
Output is correct |
61 |
Correct |
80 ms |
4416 KB |
Output is correct |
62 |
Correct |
79 ms |
3860 KB |
Output is correct |
63 |
Correct |
86 ms |
4416 KB |
Output is correct |
64 |
Correct |
34 ms |
2628 KB |
Output is correct |
65 |
Correct |
31 ms |
2728 KB |
Output is correct |
66 |
Correct |
51 ms |
2700 KB |
Output is correct |
67 |
Correct |
41 ms |
2628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4018 ms |
3884 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4074 ms |
1208 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 |
336 KB |
Output is correct |
3 |
Correct |
2 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 |
2 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 |
0 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 |
2 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 |
1 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 |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
208 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 |
32 ms |
1824 KB |
Output is correct |
37 |
Correct |
47 ms |
2712 KB |
Output is correct |
38 |
Correct |
32 ms |
2768 KB |
Output is correct |
39 |
Correct |
38 ms |
2624 KB |
Output is correct |
40 |
Correct |
29 ms |
2724 KB |
Output is correct |
41 |
Correct |
74 ms |
3348 KB |
Output is correct |
42 |
Correct |
36 ms |
2720 KB |
Output is correct |
43 |
Correct |
34 ms |
2708 KB |
Output is correct |
44 |
Correct |
21 ms |
2736 KB |
Output is correct |
45 |
Correct |
26 ms |
2708 KB |
Output is correct |
46 |
Correct |
18 ms |
2836 KB |
Output is correct |
47 |
Correct |
44 ms |
3152 KB |
Output is correct |
48 |
Correct |
33 ms |
2888 KB |
Output is correct |
49 |
Correct |
36 ms |
2724 KB |
Output is correct |
50 |
Correct |
21 ms |
2736 KB |
Output is correct |
51 |
Correct |
22 ms |
2720 KB |
Output is correct |
52 |
Correct |
74 ms |
4120 KB |
Output is correct |
53 |
Correct |
75 ms |
4760 KB |
Output is correct |
54 |
Correct |
68 ms |
4920 KB |
Output is correct |
55 |
Correct |
31 ms |
2764 KB |
Output is correct |
56 |
Correct |
40 ms |
2764 KB |
Output is correct |
57 |
Correct |
70 ms |
2944 KB |
Output is correct |
58 |
Correct |
68 ms |
3368 KB |
Output is correct |
59 |
Correct |
79 ms |
3604 KB |
Output is correct |
60 |
Correct |
80 ms |
4804 KB |
Output is correct |
61 |
Correct |
80 ms |
4416 KB |
Output is correct |
62 |
Correct |
79 ms |
3860 KB |
Output is correct |
63 |
Correct |
86 ms |
4416 KB |
Output is correct |
64 |
Correct |
34 ms |
2628 KB |
Output is correct |
65 |
Correct |
31 ms |
2728 KB |
Output is correct |
66 |
Correct |
51 ms |
2700 KB |
Output is correct |
67 |
Correct |
41 ms |
2628 KB |
Output is correct |
68 |
Execution timed out |
4018 ms |
3884 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4057 ms |
1564 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |