#include "towers.h"
#include<bits/stdc++.h>
using namespace std;
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
//#define int long long
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int mxn = 1e5 + 10, inf = 2e9 + 10;
int h[mxn], n, lg[mxn], L[mxn], R[mxn], pre[mxn], pos;
pair<int, int> p[mxn][20];
bool sub1;
pair<int, int> get(int l, int r) {
int k = lg[r - l + 1];
return max(p[l][k], p[r - (1 << k) + 1][k]);
}
void build(int l, int r) {
if(l > r) return;
int pos = get(l, r).ss;
L[pos] = l;
R[pos] = r;
if(l == r) return;
pre[pos] = 1;
build(l, pos - 1);
build(pos + 1, r);
}
void init(int _n, vector<int> H) {
n = _n;
for(int i = 1; i <= n; i++) {
h[i] = H[i - 1];
p[i][0] = {h[i], i};
}
for(int j = 1; j < 20; j++) {
for(int i = 1; i + (1 << j) - 1 <= n; i++) {
p[i][j] = max(p[i][j - 1], p[i + (1 << (j - 1))][j - 1]);
}
}
for(int i = 2; i <= n; i++) {
lg[i] = lg[i / 2] + 1;
}
build(1, n);
for(int i = 1; i <= n; i++) {
pre[i] += pre[i - 1];
}
sub1 = 1;
pos = get(1, n).ss;
for(int i = 1; i <= n; i++) {
if(L[i] < i && R[i] > i && (L[i] > 1 || R[i] < n)) sub1 = 0;
}
}
int max_towers(int l, int r, int D) {
l++;
r++;
if(l == r) return 1;
if(sub1) {
return 1 + (l < pos && r > pos && max(h[l], h[r]) <= h[pos] - D);
}
int ans = r - l + 1 - pre[r] + pre[l - 1];
if(pre[l] - pre[l - 1] == 1 && R[l] == l) ans++;
if(pre[r] - pre[r - 1] == 1 && L[r] == r) ans++;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
302 ms |
13520 KB |
Output is correct |
2 |
Correct |
579 ms |
23088 KB |
Output is correct |
3 |
Correct |
828 ms |
23112 KB |
Output is correct |
4 |
Correct |
641 ms |
23268 KB |
Output is correct |
5 |
Correct |
519 ms |
18600 KB |
Output is correct |
6 |
Correct |
628 ms |
23228 KB |
Output is correct |
7 |
Correct |
548 ms |
18596 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
336 KB |
1st lines differ - on the 1st token, expected: '13', found: '16' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
336 KB |
1st lines differ - on the 1st token, expected: '13', found: '16' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
564 ms |
18540 KB |
Output is correct |
2 |
Correct |
624 ms |
18660 KB |
Output is correct |
3 |
Correct |
552 ms |
18708 KB |
Output is correct |
4 |
Correct |
777 ms |
18656 KB |
Output is correct |
5 |
Correct |
563 ms |
18680 KB |
Output is correct |
6 |
Correct |
599 ms |
18624 KB |
Output is correct |
7 |
Correct |
642 ms |
18576 KB |
Output is correct |
8 |
Correct |
442 ms |
23352 KB |
Output is correct |
9 |
Correct |
658 ms |
18612 KB |
Output is correct |
10 |
Correct |
724 ms |
22128 KB |
Output is correct |
11 |
Correct |
742 ms |
18632 KB |
Output is correct |
12 |
Correct |
719 ms |
23336 KB |
Output is correct |
13 |
Correct |
611 ms |
18660 KB |
Output is correct |
14 |
Correct |
0 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
1 ms |
592 KB |
Output is correct |
17 |
Correct |
27 ms |
18568 KB |
Output is correct |
18 |
Correct |
26 ms |
18616 KB |
Output is correct |
19 |
Correct |
28 ms |
18672 KB |
Output is correct |
20 |
Correct |
30 ms |
18632 KB |
Output is correct |
21 |
Correct |
26 ms |
23204 KB |
Output is correct |
22 |
Correct |
27 ms |
18616 KB |
Output is correct |
23 |
Correct |
24 ms |
18600 KB |
Output is correct |
24 |
Correct |
25 ms |
18680 KB |
Output is correct |
25 |
Correct |
24 ms |
18632 KB |
Output is correct |
26 |
Correct |
26 ms |
22816 KB |
Output is correct |
27 |
Correct |
1 ms |
592 KB |
Output is correct |
28 |
Correct |
1 ms |
592 KB |
Output is correct |
29 |
Correct |
1 ms |
592 KB |
Output is correct |
30 |
Correct |
1 ms |
592 KB |
Output is correct |
31 |
Correct |
1 ms |
720 KB |
Output is correct |
32 |
Correct |
1 ms |
592 KB |
Output is correct |
33 |
Correct |
1 ms |
592 KB |
Output is correct |
34 |
Correct |
1 ms |
592 KB |
Output is correct |
35 |
Correct |
1 ms |
592 KB |
Output is correct |
36 |
Correct |
1 ms |
720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
194 ms |
4688 KB |
1st lines differ - on the 1st token, expected: '7197', found: '8004' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
336 KB |
1st lines differ - on the 1st token, expected: '13', found: '16' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
302 ms |
13520 KB |
Output is correct |
2 |
Correct |
579 ms |
23088 KB |
Output is correct |
3 |
Correct |
828 ms |
23112 KB |
Output is correct |
4 |
Correct |
641 ms |
23268 KB |
Output is correct |
5 |
Correct |
519 ms |
18600 KB |
Output is correct |
6 |
Correct |
628 ms |
23228 KB |
Output is correct |
7 |
Correct |
548 ms |
18596 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
592 KB |
Output is correct |
11 |
Incorrect |
0 ms |
336 KB |
1st lines differ - on the 1st token, expected: '13', found: '16' |
12 |
Halted |
0 ms |
0 KB |
- |