#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
struct segtree{
int k = 1;
vector<int> v;
segtree(int n){
while(k < n) k*=2;
v.assign(2*k, 0);
}
void update(int i, int x){
i+=k;
v[i] = x;
i/=2;
while(i){
v[i] = max(v[2*i], v[2*i+1]);
i/=2;
}
}
int get(int l, int r, int nd, int a, int b){
if(a > r || b < l) return 0;
if(a >= l && b <= r) return v[nd];
int md = (a+b)/2;
return max(get(l, r, 2*nd, a, md), get(l, r, 2*nd+1, md+1, b));
}
int get(int l, int r){
if(l > r) return 0;
return get(l, r, 1, 0, k-1);
}
};
int n;
vector<int> h;
segtree seg(0);
vector<int> o;
vector<int> diffs;
void init(int _n, vector<int> _h){
swap(n, _n);
swap(h, _h);
seg = segtree(n);
for(int i = 0; i < n; i++) seg.update(i, h[i]);
for(int i = 0; i < n; i++) o.pb(i);
sort(o.begin(), o.end(), [&](int a, int b){
return h[a] < h[b];
});
set<int> s;
for(int i: o){
auto it = s.upper_bound(i);
int x = 2e9;
bool ok = 1;
if(it != s.end()){
int y = seg.get(i+1, *it-1);
if(y < h[i]) ok = 0;
x = min(x, y-h[i]);
}
if(it != s.begin()){
int y = seg.get(*prev(it)+1, i-1);
if(y < h[i]) ok = 0;
x = min(x, y-h[i]);
}
if(ok) s.insert(i), diffs.pb(x);
}
sort(diffs.begin(), diffs.end());
}
int max_towers(int L, int R, int D){
return int(diffs.size())-(lower_bound(diffs.begin(), diffs.end(), D)-diffs.begin());
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
347 ms |
1640 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 |
208 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 |
208 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 |
755 ms |
4288 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 |
340 ms |
1260 KB |
Output is correct |
2 |
Correct |
903 ms |
4304 KB |
Output is correct |
3 |
Correct |
928 ms |
4404 KB |
Output is correct |
4 |
Correct |
1097 ms |
5044 KB |
Output is correct |
5 |
Correct |
1000 ms |
5040 KB |
Output is correct |
6 |
Correct |
992 ms |
5048 KB |
Output is correct |
7 |
Correct |
922 ms |
5040 KB |
Output is correct |
8 |
Correct |
947 ms |
2708 KB |
Output is correct |
9 |
Correct |
968 ms |
2716 KB |
Output is correct |
10 |
Correct |
941 ms |
2844 KB |
Output is correct |
11 |
Correct |
825 ms |
2764 KB |
Output is correct |
12 |
Correct |
89 ms |
4240 KB |
Output is correct |
13 |
Correct |
73 ms |
4924 KB |
Output is correct |
14 |
Correct |
95 ms |
5004 KB |
Output is correct |
15 |
Correct |
45 ms |
2708 KB |
Output is correct |
16 |
Correct |
39 ms |
2724 KB |
Output is correct |
17 |
Correct |
73 ms |
4032 KB |
Output is correct |
18 |
Correct |
85 ms |
4288 KB |
Output is correct |
19 |
Correct |
74 ms |
4288 KB |
Output is correct |
20 |
Correct |
72 ms |
4928 KB |
Output is correct |
21 |
Correct |
75 ms |
5044 KB |
Output is correct |
22 |
Correct |
102 ms |
5164 KB |
Output is correct |
23 |
Correct |
74 ms |
4944 KB |
Output is correct |
24 |
Correct |
32 ms |
2712 KB |
Output is correct |
25 |
Correct |
40 ms |
2732 KB |
Output is correct |
26 |
Correct |
46 ms |
2708 KB |
Output is correct |
27 |
Correct |
35 ms |
2724 KB |
Output is correct |
28 |
Correct |
2 ms |
384 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 |
208 KB |
Output is correct |
34 |
Correct |
2 ms |
336 KB |
Output is correct |
35 |
Correct |
2 ms |
336 KB |
Output is correct |
36 |
Correct |
2 ms |
336 KB |
Output is correct |
37 |
Correct |
2 ms |
336 KB |
Output is correct |
38 |
Correct |
2 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
208 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 |
347 ms |
1640 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |