#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
const int maxl = 20;
int lt[maxn],rt[maxn],mn[maxn];
vector<int> edge[maxn];
vector<pair<int,int>> res;
void init(int N, std::vector<int> H){
vector<int> v;
for(int i=0;i<N;i++){
while(!v.empty() && H[v.back()]<H[i]) v.pop_back();
lt[i]=(v.empty()?-1:v.back());
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();
rt[i]=(v.empty()?-1:v.back());
v.push_back(i);
}
int root=-1;
for(int i=0;i<N;i++){
if(lt[i]==-1 && rt[i]==-1) root=i;
else if(lt[i]==-1 || (rt[i]!=-1 && H[rt[i]]<H[lt[i]])) edge[rt[i]].push_back(i);
else edge[lt[i]].push_back(i);
}
function<void(int,int)> dfs = [&](int u,int p){
mn[u]=u;
for(int v:edge[u]){
dfs(v,u);
if(H[mn[v]]<H[mn[u]]) mn[u]=mn[v];
}
res.push_back({H[u]-H[mn[u]],1});
if(p!=-1) res.push_back({H[p]-H[mn[u]],-1});
};
dfs(root,-1);
sort(res.begin(),res.end());
for(int i=1;i<(int)res.size();i++) res[i].second+=res[i-1].second;
}
int max_towers(int L, int R, int D){
int pos=lower_bound(res.begin(),res.end(),make_pair(D,0))-res.begin()-1;
return res[pos].second;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
293 ms |
12496 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
443 ms |
8660 KB |
1st lines differ - on the 1st token, expected: '11903', found: '33010' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
197 ms |
4312 KB |
Output is correct |
2 |
Correct |
695 ms |
8912 KB |
Output is correct |
3 |
Correct |
604 ms |
8912 KB |
Output is correct |
4 |
Correct |
644 ms |
8144 KB |
Output is correct |
5 |
Correct |
719 ms |
8232 KB |
Output is correct |
6 |
Correct |
652 ms |
8144 KB |
Output is correct |
7 |
Correct |
754 ms |
8144 KB |
Output is correct |
8 |
Correct |
607 ms |
21328 KB |
Output is correct |
9 |
Correct |
612 ms |
21320 KB |
Output is correct |
10 |
Correct |
583 ms |
16720 KB |
Output is correct |
11 |
Correct |
593 ms |
17744 KB |
Output is correct |
12 |
Correct |
30 ms |
8660 KB |
Output is correct |
13 |
Correct |
26 ms |
8400 KB |
Output is correct |
14 |
Correct |
28 ms |
8168 KB |
Output is correct |
15 |
Correct |
24 ms |
21328 KB |
Output is correct |
16 |
Correct |
35 ms |
20176 KB |
Output is correct |
17 |
Correct |
30 ms |
8652 KB |
Output is correct |
18 |
Correct |
36 ms |
8656 KB |
Output is correct |
19 |
Correct |
30 ms |
8784 KB |
Output is correct |
20 |
Correct |
27 ms |
8144 KB |
Output is correct |
21 |
Correct |
28 ms |
8144 KB |
Output is correct |
22 |
Correct |
24 ms |
8144 KB |
Output is correct |
23 |
Correct |
33 ms |
8144 KB |
Output is correct |
24 |
Correct |
23 ms |
21344 KB |
Output is correct |
25 |
Correct |
26 ms |
21328 KB |
Output is correct |
26 |
Correct |
28 ms |
16716 KB |
Output is correct |
27 |
Correct |
26 ms |
20592 KB |
Output is correct |
28 |
Correct |
1 ms |
2904 KB |
Output is correct |
29 |
Correct |
1 ms |
2904 KB |
Output is correct |
30 |
Correct |
1 ms |
2904 KB |
Output is correct |
31 |
Correct |
1 ms |
3160 KB |
Output is correct |
32 |
Correct |
1 ms |
2904 KB |
Output is correct |
33 |
Correct |
1 ms |
2648 KB |
Output is correct |
34 |
Correct |
1 ms |
2904 KB |
Output is correct |
35 |
Correct |
1 ms |
2904 KB |
Output is correct |
36 |
Correct |
1 ms |
2904 KB |
Output is correct |
37 |
Correct |
1 ms |
2904 KB |
Output is correct |
38 |
Correct |
1 ms |
2904 KB |
Output is correct |
39 |
Correct |
1 ms |
2904 KB |
Output is correct |
40 |
Correct |
1 ms |
3160 KB |
Output is correct |
41 |
Correct |
1 ms |
3160 KB |
Output is correct |
42 |
Correct |
1 ms |
2904 KB |
Output is correct |
43 |
Correct |
1 ms |
3160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
293 ms |
12496 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |