This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// AM + DG
#include "towers.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vpi> vvpi;
typedef vector<vpll> vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef short int si;
typedef vector<si> vsi;
typedef vector<vsi> vvsi;
#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define L(varll, mn, mx) for(ll varll = (mn); varll < (mx); varll++)
#define LR(varll, mx, mn) for(ll varll = (mx); varll > (mn); varll--)
#define LI(vari, mn, mx) for(int vari = (mn); vari < (mx); vari++)
#define LIR(vari, mx, mn) for(int vari = (mx); vari > (mn); vari--)
#define INPV(varvec) for(auto& varveci : (varvec)) cin >> varveci
#define fi first
#define se second
#define pb push_back
#define INF(type) numeric_limits<type>::max()
#define NINF(type) numeric_limits<type>::min()
#define TCASES int t; cin >> t; while(t--)
int n;
vi h;
vi inds;
void init(int N, vi H) {
n = N;
h = H;
for(int i = 0; i < n; i++) {
if((i == 0 || h[i] < h[i - 1]) && (i == n - 1 || h[i] < h[i + 1])) {
inds.pb(i);
}
}
}
int max_towers(int L, int R, int D) {
int inds_sz = inds.size();
int l1 = -1, r1 = inds_sz;
while(r1 - l1 > 1) {
int m = (l1 + r1) >> 1;
if(inds[m] >= L) r1 = m;
else l1 = m;
}
int l2 = -1, r2 = inds_sz;
while(r2 - l2 > 1) {
int m = (l2 + r2) >> 1;
if(inds[m] <= R) l2 = m;
else r2 = m;
}
int ans = 0;
if(r1 > l2) {
// None found, just do the special case
if(L == R) ans = 0;
else {
if(h[L] <= h[L + 1]) ans++;
if(h[R] <= h[R - 1]) ans++;
}
} else {
// We got some !!
int lv = inds[r1], rv = inds[l2];
ans += l2 - r1 + 1;
if(L != lv && h[L] <= h[L + 1]) ans++;
if(R != rv && h[R] <= h[R - 1]) ans++;
}
return max(ans, 1);
}
/*
The last frontier
*/
# | 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... |