#include "towers.h"
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fr first
#define sc second
const int maxn = 1e5+10;
const int inf = 1e9+10;
int n, a[maxn];
pair<int,int> trmn[4*maxn], trmx[4*maxn];
void att(int no, int l, int r, int pos, int val) {
if(l > pos || r < pos) return;
if(l == r) {
trmn[no] = mp(val,pos);
trmx[no] = mp(val,pos);
return;
}
int f1=2*no,f2=2*no+1,mid=(l+r)/2;
att(f1,l,mid,pos,val);
att(f2,mid+1,r,pos,val);
trmn[no] = min(trmn[f1],trmn[f2]);
trmx[no] = max(trmx[f1],trmx[f2]);
}
pair<int,int> qrmn(int no, int l, int r, int L, int R) {
if(l > R || r < L) return mp(inf,0);
if(l >= L && r <= R) return trmn[no];
int f1=2*no,f2=2*no+1,mid=(l+r)/2;
return min(qrmn(f1,l,mid,L,R),qrmn(f2,mid+1,r,L,R));
}
pair<int,int> qrmx(int no, int l, int r, int L, int R) {
if(l > R || r < L) return mp(-inf,0);
if(l >= L && r <= R) return trmx[no];
int f1=2*no,f2=2*no+1,mid=(l+r)/2;
return max(qrmx(f1,l,mid,L,R),qrmx(f2,mid+1,r,L,R));
}
void init(int N, vector<int> H) {
n = N;
for(int i = 0; i < n; i++) {
a[i] = H[i];
att(1,0,n-1,i,a[i]);
}
}
int sol(int l, int r, int d) {
int i = qrmx(1,0,n-1,l,r).sc;
int ans = 0;
if(i != l && qrmn(1,0,n-1,l,i-1).fr <= a[i]-d) ans+= max(1,sol(l,i-1,d));
if(i != r && qrmn(1,0,n-1,i+1,r).fr <= a[i]-d) ans+= max(1,sol(i+1,r,d));
// cout << l << " " << r << " " << d << " " << ans << endl;
return ans;
}
int max_towers(int L, int R, int D) {
return max(1,sol(L,R,D));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4022 ms |
5016 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 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 |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 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 |
2 ms |
464 KB |
Output is correct |
24 |
Correct |
2 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
336 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 |
2 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 |
464 KB |
Output is correct |
33 |
Correct |
2 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
2 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 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 |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 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 |
2 ms |
464 KB |
Output is correct |
24 |
Correct |
2 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
336 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 |
2 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 |
464 KB |
Output is correct |
33 |
Correct |
2 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
2 ms |
464 KB |
Output is correct |
36 |
Correct |
32 ms |
3120 KB |
Output is correct |
37 |
Correct |
44 ms |
5560 KB |
Output is correct |
38 |
Correct |
53 ms |
5540 KB |
Output is correct |
39 |
Correct |
33 ms |
5544 KB |
Output is correct |
40 |
Correct |
36 ms |
5548 KB |
Output is correct |
41 |
Correct |
59 ms |
5560 KB |
Output is correct |
42 |
Correct |
37 ms |
5576 KB |
Output is correct |
43 |
Correct |
60 ms |
6668 KB |
Output is correct |
44 |
Correct |
32 ms |
5552 KB |
Output is correct |
45 |
Correct |
33 ms |
5564 KB |
Output is correct |
46 |
Correct |
32 ms |
5512 KB |
Output is correct |
47 |
Correct |
48 ms |
5576 KB |
Output is correct |
48 |
Correct |
50 ms |
5580 KB |
Output is correct |
49 |
Correct |
35 ms |
5576 KB |
Output is correct |
50 |
Correct |
41 ms |
6208 KB |
Output is correct |
51 |
Correct |
62 ms |
6900 KB |
Output is correct |
52 |
Correct |
73 ms |
5552 KB |
Output is correct |
53 |
Correct |
81 ms |
5580 KB |
Output is correct |
54 |
Correct |
66 ms |
5448 KB |
Output is correct |
55 |
Correct |
69 ms |
9888 KB |
Output is correct |
56 |
Correct |
95 ms |
9372 KB |
Output is correct |
57 |
Correct |
50 ms |
5480 KB |
Output is correct |
58 |
Correct |
64 ms |
5544 KB |
Output is correct |
59 |
Correct |
64 ms |
5544 KB |
Output is correct |
60 |
Correct |
66 ms |
5448 KB |
Output is correct |
61 |
Correct |
74 ms |
5576 KB |
Output is correct |
62 |
Correct |
79 ms |
5576 KB |
Output is correct |
63 |
Correct |
75 ms |
5568 KB |
Output is correct |
64 |
Correct |
43 ms |
7372 KB |
Output is correct |
65 |
Correct |
45 ms |
7200 KB |
Output is correct |
66 |
Correct |
51 ms |
6968 KB |
Output is correct |
67 |
Correct |
46 ms |
7352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4014 ms |
5512 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4058 ms |
1584 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 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 |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 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 |
2 ms |
464 KB |
Output is correct |
24 |
Correct |
2 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
336 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 |
2 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 |
464 KB |
Output is correct |
33 |
Correct |
2 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
2 ms |
464 KB |
Output is correct |
36 |
Correct |
32 ms |
3120 KB |
Output is correct |
37 |
Correct |
44 ms |
5560 KB |
Output is correct |
38 |
Correct |
53 ms |
5540 KB |
Output is correct |
39 |
Correct |
33 ms |
5544 KB |
Output is correct |
40 |
Correct |
36 ms |
5548 KB |
Output is correct |
41 |
Correct |
59 ms |
5560 KB |
Output is correct |
42 |
Correct |
37 ms |
5576 KB |
Output is correct |
43 |
Correct |
60 ms |
6668 KB |
Output is correct |
44 |
Correct |
32 ms |
5552 KB |
Output is correct |
45 |
Correct |
33 ms |
5564 KB |
Output is correct |
46 |
Correct |
32 ms |
5512 KB |
Output is correct |
47 |
Correct |
48 ms |
5576 KB |
Output is correct |
48 |
Correct |
50 ms |
5580 KB |
Output is correct |
49 |
Correct |
35 ms |
5576 KB |
Output is correct |
50 |
Correct |
41 ms |
6208 KB |
Output is correct |
51 |
Correct |
62 ms |
6900 KB |
Output is correct |
52 |
Correct |
73 ms |
5552 KB |
Output is correct |
53 |
Correct |
81 ms |
5580 KB |
Output is correct |
54 |
Correct |
66 ms |
5448 KB |
Output is correct |
55 |
Correct |
69 ms |
9888 KB |
Output is correct |
56 |
Correct |
95 ms |
9372 KB |
Output is correct |
57 |
Correct |
50 ms |
5480 KB |
Output is correct |
58 |
Correct |
64 ms |
5544 KB |
Output is correct |
59 |
Correct |
64 ms |
5544 KB |
Output is correct |
60 |
Correct |
66 ms |
5448 KB |
Output is correct |
61 |
Correct |
74 ms |
5576 KB |
Output is correct |
62 |
Correct |
79 ms |
5576 KB |
Output is correct |
63 |
Correct |
75 ms |
5568 KB |
Output is correct |
64 |
Correct |
43 ms |
7372 KB |
Output is correct |
65 |
Correct |
45 ms |
7200 KB |
Output is correct |
66 |
Correct |
51 ms |
6968 KB |
Output is correct |
67 |
Correct |
46 ms |
7352 KB |
Output is correct |
68 |
Execution timed out |
4014 ms |
5512 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4022 ms |
5016 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |