#include "towers.h"
#include <bits/stdc++.h>
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
struct ST{
vector<int> st;
void init(int x){
st.resize(4*x);
}
void update(int v,int L,int R,int p,int k){
if(L==R){
st[v]=k;
return;
}
int m=(L+R)/2;
if(p<=m){
update(2*v+1,L,m,p,k);
}
else{
update(2*v+2,m+1,R,p,k);
}
st[v]=max(st[2*v+1],st[2*v+2]);
}
int query(int v,int L,int R,int l,int r){
if(l>r){
return 0;
}
if(L==l && r==R){
return st[v];
}
int m=(L+R)/2;
if(r<=m){
return query(2*v+1,L,m,l,r);
}
else if(l>m){
return query(2*v+2,m+1,R,l,r);
}
else{
return max(query(2*v+1,L,m,l,m),query(2*v+2,m+1,R,m+1,r));
}
}
};
vector<int> v;
int mx;
int n;
void init(int N, vector<int> h) {
v=h;
n=N;
}
int max_towers(int l, int r, int d) {
ST st;
st.init(n);
vector<int> a(n,l);
set<pair<int,int> > s;
for(int i=r;i>=l;i--){
while(s.size()){
auto h=*s.begin();
if(h.fs+d<=v[i]){
a[h.sc]=i;
s.erase(h);
}
else{
break;
}
}
s.insert({v[i],i});
}
vector<int> dp(n);
s.clear();
int ans=0;
for(int i=l;i<=r;i++){
while(s.size()){
auto h=*s.begin();
if(h.fs+d<=v[i]){
st.update(0,0,n-1,h.sc,dp[h.sc]);
s.erase(h);
}
else{
break;
}
}
dp[i]=st.query(0,0,n-1,l,a[i]-1)+1;
s.insert({v[i],i});
ans=max(ans,dp[i]);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4083 ms |
4692 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 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 |
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 |
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 |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 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 |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
2 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 |
336 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 |
0 ms |
208 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 |
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 |
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 |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 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 |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
2 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 |
336 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 |
14 ms |
2384 KB |
Output is correct |
37 |
Correct |
31 ms |
4588 KB |
Output is correct |
38 |
Correct |
22 ms |
3628 KB |
Output is correct |
39 |
Correct |
25 ms |
4808 KB |
Output is correct |
40 |
Correct |
16 ms |
3472 KB |
Output is correct |
41 |
Correct |
55 ms |
5368 KB |
Output is correct |
42 |
Correct |
14 ms |
3368 KB |
Output is correct |
43 |
Correct |
28 ms |
5804 KB |
Output is correct |
44 |
Correct |
20 ms |
4000 KB |
Output is correct |
45 |
Correct |
12 ms |
3508 KB |
Output is correct |
46 |
Correct |
11 ms |
3440 KB |
Output is correct |
47 |
Correct |
22 ms |
3372 KB |
Output is correct |
48 |
Correct |
23 ms |
3368 KB |
Output is correct |
49 |
Correct |
13 ms |
3348 KB |
Output is correct |
50 |
Correct |
16 ms |
4392 KB |
Output is correct |
51 |
Correct |
25 ms |
5224 KB |
Output is correct |
52 |
Correct |
38 ms |
3428 KB |
Output is correct |
53 |
Correct |
38 ms |
3368 KB |
Output is correct |
54 |
Correct |
38 ms |
3392 KB |
Output is correct |
55 |
Correct |
33 ms |
8016 KB |
Output is correct |
56 |
Correct |
46 ms |
7296 KB |
Output is correct |
57 |
Correct |
55 ms |
6192 KB |
Output is correct |
58 |
Correct |
53 ms |
5392 KB |
Output is correct |
59 |
Correct |
55 ms |
4560 KB |
Output is correct |
60 |
Correct |
46 ms |
3372 KB |
Output is correct |
61 |
Correct |
47 ms |
4496 KB |
Output is correct |
62 |
Correct |
54 ms |
5392 KB |
Output is correct |
63 |
Correct |
50 ms |
4444 KB |
Output is correct |
64 |
Correct |
41 ms |
8116 KB |
Output is correct |
65 |
Correct |
43 ms |
8000 KB |
Output is correct |
66 |
Correct |
43 ms |
7320 KB |
Output is correct |
67 |
Correct |
39 ms |
8056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4011 ms |
3792 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4099 ms |
2128 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 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 |
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 |
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 |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 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 |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
2 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 |
336 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 |
14 ms |
2384 KB |
Output is correct |
37 |
Correct |
31 ms |
4588 KB |
Output is correct |
38 |
Correct |
22 ms |
3628 KB |
Output is correct |
39 |
Correct |
25 ms |
4808 KB |
Output is correct |
40 |
Correct |
16 ms |
3472 KB |
Output is correct |
41 |
Correct |
55 ms |
5368 KB |
Output is correct |
42 |
Correct |
14 ms |
3368 KB |
Output is correct |
43 |
Correct |
28 ms |
5804 KB |
Output is correct |
44 |
Correct |
20 ms |
4000 KB |
Output is correct |
45 |
Correct |
12 ms |
3508 KB |
Output is correct |
46 |
Correct |
11 ms |
3440 KB |
Output is correct |
47 |
Correct |
22 ms |
3372 KB |
Output is correct |
48 |
Correct |
23 ms |
3368 KB |
Output is correct |
49 |
Correct |
13 ms |
3348 KB |
Output is correct |
50 |
Correct |
16 ms |
4392 KB |
Output is correct |
51 |
Correct |
25 ms |
5224 KB |
Output is correct |
52 |
Correct |
38 ms |
3428 KB |
Output is correct |
53 |
Correct |
38 ms |
3368 KB |
Output is correct |
54 |
Correct |
38 ms |
3392 KB |
Output is correct |
55 |
Correct |
33 ms |
8016 KB |
Output is correct |
56 |
Correct |
46 ms |
7296 KB |
Output is correct |
57 |
Correct |
55 ms |
6192 KB |
Output is correct |
58 |
Correct |
53 ms |
5392 KB |
Output is correct |
59 |
Correct |
55 ms |
4560 KB |
Output is correct |
60 |
Correct |
46 ms |
3372 KB |
Output is correct |
61 |
Correct |
47 ms |
4496 KB |
Output is correct |
62 |
Correct |
54 ms |
5392 KB |
Output is correct |
63 |
Correct |
50 ms |
4444 KB |
Output is correct |
64 |
Correct |
41 ms |
8116 KB |
Output is correct |
65 |
Correct |
43 ms |
8000 KB |
Output is correct |
66 |
Correct |
43 ms |
7320 KB |
Output is correct |
67 |
Correct |
39 ms |
8056 KB |
Output is correct |
68 |
Execution timed out |
4011 ms |
3792 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4083 ms |
4692 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |