#include "towers.h"
#include<bits/stdc++.h>
using namespace std;
const int lim = 1e5 + 5;
template<class T>void maximize(T& a, T b){
if(a < b){
a = b;
}
}
int n, k, log_v[lim], h[lim], pref[lim], spt[lim][17];
void init(int N, vector<int>H) {
n = N;
log_v[0] = -1;
for(int i = 0; i < n; i++){
spt[i + 1][0] = h[i + 1] = H[i];
log_v[i + 1] = log_v[(i + 1) >> 1] + 1;
}
for(int j = 1; j < 17; j++){
for(int i = 1; i + (1 << j) - 1 <= n; i++){
spt[i][j] = max(spt[i][j - 1], spt[i + (1 << (j - 1))][j - 1]);
}
}
spt[0][0] = spt[n + 1][0] = INT_MAX;
pref[0] = 0;
for(int i = 1; i <= n; i++){
pref[i] = pref[i - 1] + int(spt[i][0] < spt[i - 1][0] && spt[i][0] < spt[i + 1][0]);
}
}
int get_max(int l, int r){
int k = log_v[r - l + 1];
return max(spt[l][k], spt[r - (1 << k) + 1][k]);
}
int max_towers(int l, int r, int d){
return ++l == ++r ? 1 : pref[r - 1] - pref[l + 1] + int(spt[l][0] < spt[l + 1][0]) + int(spt[r][0] < spt[r - 1][0]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |