#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
const int maxl = 20;
int N,D=-1;
vector<int> H;
int nxt[maxn][maxl],lt[maxn],rt[maxn];
void build(int _D){
vector<int> v;D=_D;
for(int i=0;i<=N;i++) lt[i]=rt[i]=-1,nxt[i][0]=N;
for(int i=0;i<N;i++){
while(!v.empty() && H[v.back()]>H[i]) v.pop_back();
int l=0,r=(int)v.size()-1;
while(l<=r){
int mid=(l+r)>>1;
if(H[v[mid]]<=H[i]-D) lt[i]=v[mid],l=mid+1;
else r=mid-1;
}
v.push_back(i);
}
v.clear();
for(int i=N-1;i>=0;i--){
while(!v.empty() && H[v.back()]>H[i]) v.pop_back();
int l=0,r=(int)v.size()-1;
while(l<=r){
int mid=(l+r)>>1;
if(H[v[mid]]<=H[i]-D) rt[i]=v[mid],l=mid+1;
else r=mid-1;
}
v.push_back(i);
}
for(int i=0;i<N;i++){
if(lt[i]==-1 || rt[i]==-1) continue;
nxt[lt[i]][0]=min(nxt[lt[i]][0],rt[i]);
}
for(int i=N-1;i>=0;i--) nxt[i][0]=min(nxt[i][0],nxt[i+1][0]);
for(int i=1;i<18;i++) for(int j=0;j<=N;j++) nxt[j][i]=nxt[nxt[j][i-1]][i-1];
}
void init(int _N, std::vector<int> _H){
N=_N;H=_H;
}
int max_towers(int L, int R, int _D){
if(_D!=D) build(_D);
int cnt=1;
for(int i=17;i>=0;i--){
if(nxt[L][i]<=R) L=nxt[L][i],cnt+=(1<<i);
}
return cnt;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4070 ms |
7912 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
0 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2392 KB |
Output is correct |
25 |
Correct |
0 ms |
2392 KB |
Output is correct |
26 |
Correct |
1 ms |
2392 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
0 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2392 KB |
Output is correct |
25 |
Correct |
0 ms |
2392 KB |
Output is correct |
26 |
Correct |
1 ms |
2392 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
1 ms |
2392 KB |
Output is correct |
36 |
Correct |
11 ms |
7256 KB |
Output is correct |
37 |
Correct |
16 ms |
9680 KB |
Output is correct |
38 |
Correct |
25 ms |
9680 KB |
Output is correct |
39 |
Correct |
14 ms |
9680 KB |
Output is correct |
40 |
Correct |
17 ms |
9668 KB |
Output is correct |
41 |
Correct |
20 ms |
9836 KB |
Output is correct |
42 |
Correct |
15 ms |
9664 KB |
Output is correct |
43 |
Correct |
17 ms |
10704 KB |
Output is correct |
44 |
Correct |
18 ms |
10704 KB |
Output is correct |
45 |
Correct |
14 ms |
10176 KB |
Output is correct |
46 |
Correct |
20 ms |
10192 KB |
Output is correct |
47 |
Correct |
15 ms |
9680 KB |
Output is correct |
48 |
Correct |
15 ms |
9780 KB |
Output is correct |
49 |
Correct |
14 ms |
9680 KB |
Output is correct |
50 |
Correct |
16 ms |
10624 KB |
Output is correct |
51 |
Correct |
15 ms |
10704 KB |
Output is correct |
52 |
Correct |
16 ms |
9676 KB |
Output is correct |
53 |
Correct |
16 ms |
9680 KB |
Output is correct |
54 |
Correct |
23 ms |
9680 KB |
Output is correct |
55 |
Correct |
16 ms |
10552 KB |
Output is correct |
56 |
Correct |
20 ms |
10192 KB |
Output is correct |
57 |
Correct |
15 ms |
9436 KB |
Output is correct |
58 |
Correct |
16 ms |
9680 KB |
Output is correct |
59 |
Correct |
16 ms |
9680 KB |
Output is correct |
60 |
Correct |
15 ms |
9680 KB |
Output is correct |
61 |
Correct |
16 ms |
9680 KB |
Output is correct |
62 |
Correct |
20 ms |
9680 KB |
Output is correct |
63 |
Correct |
16 ms |
9680 KB |
Output is correct |
64 |
Correct |
15 ms |
10704 KB |
Output is correct |
65 |
Correct |
16 ms |
10704 KB |
Output is correct |
66 |
Correct |
25 ms |
10276 KB |
Output is correct |
67 |
Correct |
15 ms |
10704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
548 ms |
9684 KB |
Output is correct |
2 |
Correct |
680 ms |
9680 KB |
Output is correct |
3 |
Correct |
673 ms |
9680 KB |
Output is correct |
4 |
Correct |
689 ms |
9680 KB |
Output is correct |
5 |
Correct |
681 ms |
9680 KB |
Output is correct |
6 |
Correct |
669 ms |
9680 KB |
Output is correct |
7 |
Correct |
687 ms |
9680 KB |
Output is correct |
8 |
Correct |
682 ms |
10700 KB |
Output is correct |
9 |
Correct |
622 ms |
10704 KB |
Output is correct |
10 |
Correct |
666 ms |
10448 KB |
Output is correct |
11 |
Correct |
675 ms |
10448 KB |
Output is correct |
12 |
Correct |
659 ms |
10704 KB |
Output is correct |
13 |
Correct |
692 ms |
10696 KB |
Output is correct |
14 |
Correct |
0 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
20 ms |
9828 KB |
Output is correct |
18 |
Correct |
13 ms |
9680 KB |
Output is correct |
19 |
Correct |
13 ms |
9680 KB |
Output is correct |
20 |
Correct |
13 ms |
10704 KB |
Output is correct |
21 |
Correct |
13 ms |
10740 KB |
Output is correct |
22 |
Correct |
20 ms |
9840 KB |
Output is correct |
23 |
Correct |
13 ms |
9680 KB |
Output is correct |
24 |
Correct |
16 ms |
9676 KB |
Output is correct |
25 |
Correct |
20 ms |
10704 KB |
Output is correct |
26 |
Correct |
14 ms |
10192 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
0 ms |
2392 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
1 ms |
2392 KB |
Output is correct |
36 |
Correct |
0 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4054 ms |
4952 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
2 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
0 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2392 KB |
Output is correct |
25 |
Correct |
0 ms |
2392 KB |
Output is correct |
26 |
Correct |
1 ms |
2392 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
1 ms |
2392 KB |
Output is correct |
36 |
Correct |
11 ms |
7256 KB |
Output is correct |
37 |
Correct |
16 ms |
9680 KB |
Output is correct |
38 |
Correct |
25 ms |
9680 KB |
Output is correct |
39 |
Correct |
14 ms |
9680 KB |
Output is correct |
40 |
Correct |
17 ms |
9668 KB |
Output is correct |
41 |
Correct |
20 ms |
9836 KB |
Output is correct |
42 |
Correct |
15 ms |
9664 KB |
Output is correct |
43 |
Correct |
17 ms |
10704 KB |
Output is correct |
44 |
Correct |
18 ms |
10704 KB |
Output is correct |
45 |
Correct |
14 ms |
10176 KB |
Output is correct |
46 |
Correct |
20 ms |
10192 KB |
Output is correct |
47 |
Correct |
15 ms |
9680 KB |
Output is correct |
48 |
Correct |
15 ms |
9780 KB |
Output is correct |
49 |
Correct |
14 ms |
9680 KB |
Output is correct |
50 |
Correct |
16 ms |
10624 KB |
Output is correct |
51 |
Correct |
15 ms |
10704 KB |
Output is correct |
52 |
Correct |
16 ms |
9676 KB |
Output is correct |
53 |
Correct |
16 ms |
9680 KB |
Output is correct |
54 |
Correct |
23 ms |
9680 KB |
Output is correct |
55 |
Correct |
16 ms |
10552 KB |
Output is correct |
56 |
Correct |
20 ms |
10192 KB |
Output is correct |
57 |
Correct |
15 ms |
9436 KB |
Output is correct |
58 |
Correct |
16 ms |
9680 KB |
Output is correct |
59 |
Correct |
16 ms |
9680 KB |
Output is correct |
60 |
Correct |
15 ms |
9680 KB |
Output is correct |
61 |
Correct |
16 ms |
9680 KB |
Output is correct |
62 |
Correct |
20 ms |
9680 KB |
Output is correct |
63 |
Correct |
16 ms |
9680 KB |
Output is correct |
64 |
Correct |
15 ms |
10704 KB |
Output is correct |
65 |
Correct |
16 ms |
10704 KB |
Output is correct |
66 |
Correct |
25 ms |
10276 KB |
Output is correct |
67 |
Correct |
15 ms |
10704 KB |
Output is correct |
68 |
Correct |
548 ms |
9684 KB |
Output is correct |
69 |
Correct |
680 ms |
9680 KB |
Output is correct |
70 |
Correct |
673 ms |
9680 KB |
Output is correct |
71 |
Correct |
689 ms |
9680 KB |
Output is correct |
72 |
Correct |
681 ms |
9680 KB |
Output is correct |
73 |
Correct |
669 ms |
9680 KB |
Output is correct |
74 |
Correct |
687 ms |
9680 KB |
Output is correct |
75 |
Correct |
682 ms |
10700 KB |
Output is correct |
76 |
Correct |
622 ms |
10704 KB |
Output is correct |
77 |
Correct |
666 ms |
10448 KB |
Output is correct |
78 |
Correct |
675 ms |
10448 KB |
Output is correct |
79 |
Correct |
659 ms |
10704 KB |
Output is correct |
80 |
Correct |
692 ms |
10696 KB |
Output is correct |
81 |
Correct |
0 ms |
2392 KB |
Output is correct |
82 |
Correct |
1 ms |
2392 KB |
Output is correct |
83 |
Correct |
1 ms |
2392 KB |
Output is correct |
84 |
Correct |
20 ms |
9828 KB |
Output is correct |
85 |
Correct |
13 ms |
9680 KB |
Output is correct |
86 |
Correct |
13 ms |
9680 KB |
Output is correct |
87 |
Correct |
13 ms |
10704 KB |
Output is correct |
88 |
Correct |
13 ms |
10740 KB |
Output is correct |
89 |
Correct |
20 ms |
9840 KB |
Output is correct |
90 |
Correct |
13 ms |
9680 KB |
Output is correct |
91 |
Correct |
16 ms |
9676 KB |
Output is correct |
92 |
Correct |
20 ms |
10704 KB |
Output is correct |
93 |
Correct |
14 ms |
10192 KB |
Output is correct |
94 |
Correct |
1 ms |
2392 KB |
Output is correct |
95 |
Correct |
1 ms |
2392 KB |
Output is correct |
96 |
Correct |
1 ms |
2392 KB |
Output is correct |
97 |
Correct |
1 ms |
2392 KB |
Output is correct |
98 |
Correct |
1 ms |
2392 KB |
Output is correct |
99 |
Correct |
0 ms |
2392 KB |
Output is correct |
100 |
Correct |
1 ms |
2392 KB |
Output is correct |
101 |
Correct |
1 ms |
2392 KB |
Output is correct |
102 |
Correct |
1 ms |
2392 KB |
Output is correct |
103 |
Correct |
0 ms |
2392 KB |
Output is correct |
104 |
Correct |
558 ms |
9468 KB |
Output is correct |
105 |
Correct |
688 ms |
9680 KB |
Output is correct |
106 |
Correct |
689 ms |
9680 KB |
Output is correct |
107 |
Correct |
685 ms |
9680 KB |
Output is correct |
108 |
Correct |
622 ms |
9680 KB |
Output is correct |
109 |
Correct |
721 ms |
9680 KB |
Output is correct |
110 |
Correct |
658 ms |
9680 KB |
Output is correct |
111 |
Correct |
612 ms |
10744 KB |
Output is correct |
112 |
Correct |
610 ms |
10704 KB |
Output is correct |
113 |
Correct |
656 ms |
10184 KB |
Output is correct |
114 |
Correct |
638 ms |
10704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4070 ms |
7912 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |