#include "towers.h"
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
const int LG=17;
int n;
int h[N],sp[LG][N];
int rmq(int l,int r){
int k=31-__builtin_clz(r-l+1);
return max(sp[k][l],sp[k][r-(1<<k)+1]);
}
void init(int N,vector<int> H){
n=N;
for(int i=1;i<=n;i++)sp[0][i]=h[i]=H[i-1];
for(int i=1;i<LG;i++){
for(int j=1;j+(1<<i)-1<=n;j++){
sp[i][j]=max(sp[i-1][j],sp[i-1][j+(1<<(i-1))]);
}
}
}
int max_towers(int L,int R,int D){
L++,R++;
vector<pair<int,int>> vec;
for(int i=L;i<=R;i++)vec.emplace_back(h[i],i);
sort(vec.begin(),vec.end());
set<int> ans;
auto lb=[&](int id){
int l=L-1,r=id-1;
while(l<r){
int m=(l+r+1)/2;
if(rmq(m,id)>=h[id]+D)l=m;
else r=m-1;
}
return l;
};
auto ub=[&](int id){
int l=id+1,r=R+1;
while(l<r){
int m=(l+r)/2;
if(rmq(id,m)>=h[id]+D)r=m;
else l=m+1;
}
return l;
};
for(auto [hei,id]:vec){
int l=lb(id),r=ub(id);
auto it=ans.lower_bound(l);
if(it==ans.end()||*it>r)ans.emplace(id);
}
return ans.size();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4078 ms |
5420 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
388 KB |
Output is correct |
2 |
Correct |
1 ms |
464 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 |
0 ms |
260 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
336 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 |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
436 KB |
Output is correct |
20 |
Correct |
1 ms |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
464 KB |
Output is correct |
23 |
Correct |
1 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
516 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
480 KB |
Output is correct |
29 |
Correct |
1 ms |
464 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
464 KB |
Output is correct |
34 |
Correct |
1 ms |
464 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
388 KB |
Output is correct |
2 |
Correct |
1 ms |
464 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 |
0 ms |
260 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
336 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 |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
436 KB |
Output is correct |
20 |
Correct |
1 ms |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
464 KB |
Output is correct |
23 |
Correct |
1 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
516 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
480 KB |
Output is correct |
29 |
Correct |
1 ms |
464 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
464 KB |
Output is correct |
34 |
Correct |
1 ms |
464 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
36 |
Correct |
14 ms |
5072 KB |
Output is correct |
37 |
Correct |
21 ms |
8056 KB |
Output is correct |
38 |
Correct |
16 ms |
7632 KB |
Output is correct |
39 |
Correct |
18 ms |
7752 KB |
Output is correct |
40 |
Correct |
22 ms |
7612 KB |
Output is correct |
41 |
Correct |
48 ms |
8776 KB |
Output is correct |
42 |
Correct |
13 ms |
7632 KB |
Output is correct |
43 |
Correct |
19 ms |
8136 KB |
Output is correct |
44 |
Correct |
14 ms |
7632 KB |
Output is correct |
45 |
Correct |
13 ms |
7632 KB |
Output is correct |
46 |
Correct |
12 ms |
7624 KB |
Output is correct |
47 |
Correct |
26 ms |
7972 KB |
Output is correct |
48 |
Correct |
27 ms |
7840 KB |
Output is correct |
49 |
Correct |
15 ms |
7632 KB |
Output is correct |
50 |
Correct |
14 ms |
7596 KB |
Output is correct |
51 |
Correct |
25 ms |
8008 KB |
Output is correct |
52 |
Correct |
65 ms |
9560 KB |
Output is correct |
53 |
Correct |
68 ms |
10300 KB |
Output is correct |
54 |
Correct |
70 ms |
10296 KB |
Output is correct |
55 |
Correct |
31 ms |
8776 KB |
Output is correct |
56 |
Correct |
27 ms |
8768 KB |
Output is correct |
57 |
Correct |
45 ms |
8532 KB |
Output is correct |
58 |
Correct |
62 ms |
9068 KB |
Output is correct |
59 |
Correct |
58 ms |
9200 KB |
Output is correct |
60 |
Correct |
69 ms |
10336 KB |
Output is correct |
61 |
Correct |
66 ms |
9912 KB |
Output is correct |
62 |
Correct |
52 ms |
9324 KB |
Output is correct |
63 |
Correct |
59 ms |
10024 KB |
Output is correct |
64 |
Correct |
34 ms |
8776 KB |
Output is correct |
65 |
Correct |
26 ms |
8776 KB |
Output is correct |
66 |
Correct |
35 ms |
8776 KB |
Output is correct |
67 |
Correct |
26 ms |
8824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4086 ms |
10036 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4081 ms |
2780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
388 KB |
Output is correct |
2 |
Correct |
1 ms |
464 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 |
0 ms |
260 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
336 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 |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
436 KB |
Output is correct |
20 |
Correct |
1 ms |
464 KB |
Output is correct |
21 |
Correct |
1 ms |
464 KB |
Output is correct |
22 |
Correct |
1 ms |
464 KB |
Output is correct |
23 |
Correct |
1 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
516 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
480 KB |
Output is correct |
29 |
Correct |
1 ms |
464 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
1 ms |
464 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
464 KB |
Output is correct |
34 |
Correct |
1 ms |
464 KB |
Output is correct |
35 |
Correct |
1 ms |
464 KB |
Output is correct |
36 |
Correct |
14 ms |
5072 KB |
Output is correct |
37 |
Correct |
21 ms |
8056 KB |
Output is correct |
38 |
Correct |
16 ms |
7632 KB |
Output is correct |
39 |
Correct |
18 ms |
7752 KB |
Output is correct |
40 |
Correct |
22 ms |
7612 KB |
Output is correct |
41 |
Correct |
48 ms |
8776 KB |
Output is correct |
42 |
Correct |
13 ms |
7632 KB |
Output is correct |
43 |
Correct |
19 ms |
8136 KB |
Output is correct |
44 |
Correct |
14 ms |
7632 KB |
Output is correct |
45 |
Correct |
13 ms |
7632 KB |
Output is correct |
46 |
Correct |
12 ms |
7624 KB |
Output is correct |
47 |
Correct |
26 ms |
7972 KB |
Output is correct |
48 |
Correct |
27 ms |
7840 KB |
Output is correct |
49 |
Correct |
15 ms |
7632 KB |
Output is correct |
50 |
Correct |
14 ms |
7596 KB |
Output is correct |
51 |
Correct |
25 ms |
8008 KB |
Output is correct |
52 |
Correct |
65 ms |
9560 KB |
Output is correct |
53 |
Correct |
68 ms |
10300 KB |
Output is correct |
54 |
Correct |
70 ms |
10296 KB |
Output is correct |
55 |
Correct |
31 ms |
8776 KB |
Output is correct |
56 |
Correct |
27 ms |
8768 KB |
Output is correct |
57 |
Correct |
45 ms |
8532 KB |
Output is correct |
58 |
Correct |
62 ms |
9068 KB |
Output is correct |
59 |
Correct |
58 ms |
9200 KB |
Output is correct |
60 |
Correct |
69 ms |
10336 KB |
Output is correct |
61 |
Correct |
66 ms |
9912 KB |
Output is correct |
62 |
Correct |
52 ms |
9324 KB |
Output is correct |
63 |
Correct |
59 ms |
10024 KB |
Output is correct |
64 |
Correct |
34 ms |
8776 KB |
Output is correct |
65 |
Correct |
26 ms |
8776 KB |
Output is correct |
66 |
Correct |
35 ms |
8776 KB |
Output is correct |
67 |
Correct |
26 ms |
8824 KB |
Output is correct |
68 |
Execution timed out |
4086 ms |
10036 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4078 ms |
5420 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |