#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, a[100100], mn[100100];
priority_queue<int> pq;
vector<int> G;
struct Seg{
pair<int, int> tree[200200];
int sz;
void init(int n){
sz = n;
for (int i=sz;i<sz*2;i++) tree[i] = {a[i-sz], i-sz};
for (int i=sz-1;i;i--) tree[i] = max(tree[i<<1], tree[i<<1|1]);
}
pair<int, int> query(int l, int r){
++r;
pair<int, int> ret = {-1, 0};
for (l+=sz, r+=sz;l<r;l>>=1, r>>=1){
if (l&1) ret = max(ret, tree[l++]);
if (r&1) ret = max(ret, tree[--r]);
}
return ret;
}
}tree;
int dnc(int l, int r){
if (l>r) return -1;
if (l==r) {mn[l] = a[l]; return l;}
auto [mx, mid] = tree.query(l, r);
int L = dnc(l, mid-1), R = dnc(mid+1, r);
if (L==-1){
mn[mid] = mn[R];
}
else if (R==-1){
mn[mid] = mn[L];
}
else{
mn[mid] = min(mn[L], mn[R]);
pq.push(mx - max(mn[L], mn[R]));
}
//printf("%d %d -> %d / %d\n", l, r, mid, mn[mid]);
return mid;
}
void init(int N, std::vector<int> H) {
n = N;
for (int i=1;i<=n;i++) a[i] = H[i-1];
tree.init(n+1);
dnc(1, n);
while(!pq.empty()){
G.push_back(pq.top()); pq.pop();
}
reverse(G.begin(), G.end());
//for (auto &x:G) printf("%d ", x);
//printf("\n");
}
int max_towers(int l, int r, int D) {
++l, ++r;
int sz = G.size();
return sz - (lower_bound(G.begin(), G.end(), D) - G.begin()) + 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
475 ms |
6600 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 |
1872 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 |
1872 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 |
611 ms |
3908 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 |
301 ms |
2328 KB |
Output is correct |
2 |
Correct |
649 ms |
3908 KB |
Output is correct |
3 |
Correct |
707 ms |
3912 KB |
Output is correct |
4 |
Correct |
581 ms |
4016 KB |
Output is correct |
5 |
Correct |
955 ms |
3912 KB |
Output is correct |
6 |
Correct |
757 ms |
3920 KB |
Output is correct |
7 |
Correct |
773 ms |
3916 KB |
Output is correct |
8 |
Correct |
859 ms |
11224 KB |
Output is correct |
9 |
Correct |
913 ms |
11232 KB |
Output is correct |
10 |
Correct |
653 ms |
8024 KB |
Output is correct |
11 |
Correct |
692 ms |
8648 KB |
Output is correct |
12 |
Correct |
19 ms |
3920 KB |
Output is correct |
13 |
Correct |
29 ms |
3916 KB |
Output is correct |
14 |
Correct |
20 ms |
3904 KB |
Output is correct |
15 |
Correct |
22 ms |
11220 KB |
Output is correct |
16 |
Correct |
22 ms |
10516 KB |
Output is correct |
17 |
Correct |
24 ms |
3668 KB |
Output is correct |
18 |
Correct |
28 ms |
3908 KB |
Output is correct |
19 |
Correct |
19 ms |
3916 KB |
Output is correct |
20 |
Correct |
19 ms |
3912 KB |
Output is correct |
21 |
Correct |
20 ms |
3912 KB |
Output is correct |
22 |
Correct |
20 ms |
3912 KB |
Output is correct |
23 |
Correct |
20 ms |
3932 KB |
Output is correct |
24 |
Correct |
22 ms |
11208 KB |
Output is correct |
25 |
Correct |
24 ms |
11196 KB |
Output is correct |
26 |
Correct |
21 ms |
8144 KB |
Output is correct |
27 |
Correct |
22 ms |
10720 KB |
Output is correct |
28 |
Correct |
1 ms |
1872 KB |
Output is correct |
29 |
Correct |
1 ms |
1872 KB |
Output is correct |
30 |
Correct |
1 ms |
1872 KB |
Output is correct |
31 |
Correct |
1 ms |
2000 KB |
Output is correct |
32 |
Correct |
2 ms |
2000 KB |
Output is correct |
33 |
Correct |
1 ms |
1872 KB |
Output is correct |
34 |
Correct |
1 ms |
1872 KB |
Output is correct |
35 |
Correct |
1 ms |
1872 KB |
Output is correct |
36 |
Correct |
1 ms |
1872 KB |
Output is correct |
37 |
Correct |
1 ms |
1872 KB |
Output is correct |
38 |
Correct |
2 ms |
1872 KB |
Output is correct |
39 |
Correct |
1 ms |
1872 KB |
Output is correct |
40 |
Correct |
1 ms |
2000 KB |
Output is correct |
41 |
Correct |
1 ms |
2000 KB |
Output is correct |
42 |
Correct |
1 ms |
2000 KB |
Output is correct |
43 |
Correct |
1 ms |
2000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1872 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 |
475 ms |
6600 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |