#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
vector<int>H,addto;
void init(int N, std::vector<int> H_) {
H=H_;
}
struct fenwickt{
int T[100100];
int qry(int n){
n++;
int ans=0;
while(n)
ans=max(ans,T[n]),n-=n&-n;
return ans;
}
void upd(int n,int p){
n++;
while(n<100100)
T[n]=max(T[n],p),n+=n&-n;
}
} ST;
vector<pair<int,int>>inser[100100];
int max_towers(int l, int r, int D) {
int n=H.size();
vector<int>stk;
stk.push_back(n);
H.push_back(2e9);
addto.resize(n);
for(int i=r;i>=l;i--){
while(H[stk.back()]<H[i])
stk.pop_back();
H[i]+=D;
addto[i]=*--upper_bound(stk.begin(),stk.end(),i,[](int a,int b){
return H[a]>H[b];
});
H[i]-=D;
stk.push_back(i);
}
int ans=0;
stk.clear();
for(int i=l;i<=r;i++){
for(auto[pos,v]:inser[i])
ST.upd(pos,v);
while(stk.size()&&H[stk.back()]<H[i])
stk.pop_back();
H[i]+=D;
auto it=upper_bound(stk.begin(),stk.end(),i,[](int a,int b){
return H[a]>H[b];
});
H[i]-=D;
int Pos=0;
if(it!=stk.begin())
Pos=*--it;
int dp=ST.qry(Pos-1)+1;
inser[addto[i]+1].push_back({i,dp});
ans=max(ans,dp);
stk.push_back(i);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4027 ms |
90836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2648 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2796 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
2 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
2 ms |
2648 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
1 ms |
2824 KB |
Output is correct |
20 |
Correct |
1 ms |
2648 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2648 KB |
Output is correct |
23 |
Correct |
1 ms |
2648 KB |
Output is correct |
24 |
Correct |
1 ms |
2904 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
1 ms |
2648 KB |
Output is correct |
29 |
Correct |
1 ms |
2648 KB |
Output is correct |
30 |
Correct |
1 ms |
2676 KB |
Output is correct |
31 |
Correct |
1 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2648 KB |
Output is correct |
33 |
Correct |
1 ms |
2648 KB |
Output is correct |
34 |
Correct |
1 ms |
2648 KB |
Output is correct |
35 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2648 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2796 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
2 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
2 ms |
2648 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
1 ms |
2824 KB |
Output is correct |
20 |
Correct |
1 ms |
2648 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2648 KB |
Output is correct |
23 |
Correct |
1 ms |
2648 KB |
Output is correct |
24 |
Correct |
1 ms |
2904 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
1 ms |
2648 KB |
Output is correct |
29 |
Correct |
1 ms |
2648 KB |
Output is correct |
30 |
Correct |
1 ms |
2676 KB |
Output is correct |
31 |
Correct |
1 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2648 KB |
Output is correct |
33 |
Correct |
1 ms |
2648 KB |
Output is correct |
34 |
Correct |
1 ms |
2648 KB |
Output is correct |
35 |
Correct |
1 ms |
2648 KB |
Output is correct |
36 |
Correct |
7 ms |
3928 KB |
Output is correct |
37 |
Correct |
16 ms |
4464 KB |
Output is correct |
38 |
Correct |
9 ms |
4168 KB |
Output is correct |
39 |
Correct |
9 ms |
4424 KB |
Output is correct |
40 |
Correct |
9 ms |
4048 KB |
Output is correct |
41 |
Correct |
20 ms |
5448 KB |
Output is correct |
42 |
Correct |
8 ms |
3928 KB |
Output is correct |
43 |
Correct |
11 ms |
5324 KB |
Output is correct |
44 |
Correct |
8 ms |
4168 KB |
Output is correct |
45 |
Correct |
8 ms |
3956 KB |
Output is correct |
46 |
Correct |
8 ms |
3928 KB |
Output is correct |
47 |
Correct |
11 ms |
4680 KB |
Output is correct |
48 |
Correct |
10 ms |
4300 KB |
Output is correct |
49 |
Correct |
9 ms |
4168 KB |
Output is correct |
50 |
Correct |
9 ms |
4168 KB |
Output is correct |
51 |
Correct |
12 ms |
5448 KB |
Output is correct |
52 |
Correct |
16 ms |
6016 KB |
Output is correct |
53 |
Correct |
15 ms |
6216 KB |
Output is correct |
54 |
Correct |
15 ms |
6096 KB |
Output is correct |
55 |
Correct |
12 ms |
5448 KB |
Output is correct |
56 |
Correct |
15 ms |
7752 KB |
Output is correct |
57 |
Correct |
22 ms |
5216 KB |
Output is correct |
58 |
Correct |
15 ms |
5448 KB |
Output is correct |
59 |
Correct |
22 ms |
5732 KB |
Output is correct |
60 |
Correct |
15 ms |
5972 KB |
Output is correct |
61 |
Correct |
21 ms |
5960 KB |
Output is correct |
62 |
Correct |
14 ms |
5684 KB |
Output is correct |
63 |
Correct |
16 ms |
6212 KB |
Output is correct |
64 |
Correct |
13 ms |
6216 KB |
Output is correct |
65 |
Correct |
11 ms |
5448 KB |
Output is correct |
66 |
Correct |
19 ms |
5984 KB |
Output is correct |
67 |
Correct |
16 ms |
5444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4067 ms |
94048 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4034 ms |
54516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
1 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2648 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2796 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
2 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
2 ms |
2648 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
1 ms |
2824 KB |
Output is correct |
20 |
Correct |
1 ms |
2648 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
1 ms |
2648 KB |
Output is correct |
23 |
Correct |
1 ms |
2648 KB |
Output is correct |
24 |
Correct |
1 ms |
2904 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
1 ms |
2648 KB |
Output is correct |
29 |
Correct |
1 ms |
2648 KB |
Output is correct |
30 |
Correct |
1 ms |
2676 KB |
Output is correct |
31 |
Correct |
1 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2648 KB |
Output is correct |
33 |
Correct |
1 ms |
2648 KB |
Output is correct |
34 |
Correct |
1 ms |
2648 KB |
Output is correct |
35 |
Correct |
1 ms |
2648 KB |
Output is correct |
36 |
Correct |
7 ms |
3928 KB |
Output is correct |
37 |
Correct |
16 ms |
4464 KB |
Output is correct |
38 |
Correct |
9 ms |
4168 KB |
Output is correct |
39 |
Correct |
9 ms |
4424 KB |
Output is correct |
40 |
Correct |
9 ms |
4048 KB |
Output is correct |
41 |
Correct |
20 ms |
5448 KB |
Output is correct |
42 |
Correct |
8 ms |
3928 KB |
Output is correct |
43 |
Correct |
11 ms |
5324 KB |
Output is correct |
44 |
Correct |
8 ms |
4168 KB |
Output is correct |
45 |
Correct |
8 ms |
3956 KB |
Output is correct |
46 |
Correct |
8 ms |
3928 KB |
Output is correct |
47 |
Correct |
11 ms |
4680 KB |
Output is correct |
48 |
Correct |
10 ms |
4300 KB |
Output is correct |
49 |
Correct |
9 ms |
4168 KB |
Output is correct |
50 |
Correct |
9 ms |
4168 KB |
Output is correct |
51 |
Correct |
12 ms |
5448 KB |
Output is correct |
52 |
Correct |
16 ms |
6016 KB |
Output is correct |
53 |
Correct |
15 ms |
6216 KB |
Output is correct |
54 |
Correct |
15 ms |
6096 KB |
Output is correct |
55 |
Correct |
12 ms |
5448 KB |
Output is correct |
56 |
Correct |
15 ms |
7752 KB |
Output is correct |
57 |
Correct |
22 ms |
5216 KB |
Output is correct |
58 |
Correct |
15 ms |
5448 KB |
Output is correct |
59 |
Correct |
22 ms |
5732 KB |
Output is correct |
60 |
Correct |
15 ms |
5972 KB |
Output is correct |
61 |
Correct |
21 ms |
5960 KB |
Output is correct |
62 |
Correct |
14 ms |
5684 KB |
Output is correct |
63 |
Correct |
16 ms |
6212 KB |
Output is correct |
64 |
Correct |
13 ms |
6216 KB |
Output is correct |
65 |
Correct |
11 ms |
5448 KB |
Output is correct |
66 |
Correct |
19 ms |
5984 KB |
Output is correct |
67 |
Correct |
16 ms |
5444 KB |
Output is correct |
68 |
Execution timed out |
4067 ms |
94048 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4027 ms |
90836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |