This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "towers.h"
#include <bits/stdc++.h>
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define fe(x, y) for (auto& x : y)
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define pw(x) (1LL << (x))
#define sz(x) (int)x.size()
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ve = vector <T>;
template <typename T>
bool umx (T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T>
bool umn (T& a, T b) { return a > b ? a = b, 1 : 0; }
using ll = long long;
using ld = long double;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
using ull = unsigned long long;
const int oo = 1e9;
const ll OO = 1e18;
const int N = 1e5 + 10;
const int M = 5e3 + 100;
const int mod = 1e9 + 7;
const bool TEST = 0;
int spars[N][20];
int h[N];
int get(int l, int r) {
int sz = r - l + 1;
return max(spars[l][__lg(sz)], spars[r - pw(__lg(sz)) + 1][__lg(sz)]);
}
void init(int N, std::vector<int> H) {
for (int i = 0; i < N; i++) h[i] = spars[i][0] = H[i];
for (int bt = 1; pw(bt) <= N; bt++) {
for (int i = 0; i <= N - pw(bt); i++) {
spars[i][bt] = max(spars[i][bt - 1], spars[i + pw(bt - 1)][bt - 1]);
}
}
}
int max_towers(int L, int R, int D) {
ve <pii> V;
for (int i = L; i <= R; i++) V.pb({h[i], i});
sort(all(V));
set <int> HAVE;
for (int i = 0; i < sz(V); i++) {
if (!sz(HAVE)) {
HAVE.insert(V[i].se);
continue;
}
auto ps = HAVE.lower_bound(V[i].se);
bool ok = 1;
if (ps != HAVE.begin()) {
--ps;
int y = *ps;
++ps;
int mx = get(y, V[i].se);
ok &= (mx - D >= V[i].fi);
}
if (ps != HAVE.end()) {
int y = *ps;
int mx = get(V[i].se, y);
ok &= (mx - D >= V[i].fi);
}
if (ok) HAVE.insert(V[i].se);
}
return sz(HAVE);
}
# | 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... |