이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "towers.h"
#include <bits/stdc++.h>
//#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long
using namespace std;
const int maxn=1e5+10,LOG=17,mod=1e9+7;
int block = 650, timer = 0;
const double eps = 1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bt(i) (1 << (i))
//#define int ll
const long long inf=2e18;
#define y1 yy
#define pii pair <int, int>
int n, a[maxn], t[4*maxn];
void build(int v, int tl, int tr)
{
if(tl == tr)
{
t[v] = a[tl];
return;
}
build(v * 2, tl, (tl + tr) / 2);
build(v * 2 + 1, (tl + tr) / 2 + 1, tr);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
int getmax(int v, int tl, int tr, int l, int r)
{
if(l <= tl && tr <= r) return t[v];
if(l > tr || r < tl) return 0;
return max(getmax(v * 2, tl, (tl + tr) / 2, l, r),
getmax(v * 2 + 1, (tl + tr) / 2 + 1, tr, l, r));
}
void init(int N, std::vector<int> H) {
n = N;
forn(1, i, n)
{
a[i] = H[i-1];
}
build(1, 1, n);
}
int Ans;
int max_towers(int l, int r, int d) {
l++;
r++;
if(l == 1 && r == n && Ans != 0) return Ans;
vector <pii> vec;
forn(l, i, r)
{
vec.pb({a[i], i});
}
sort(all(vec));
set <int> st;
st.insert(n + 1);
st.insert(0);
for(auto it : vec)
{
int pos = it.s;
auto iter = st.lower_bound(pos);
int r = *iter;
iter--;
int l = *iter;
if((l == 0 || getmax(1, 1, n, l + 1, pos-1) >= a[pos]+d) &&
(r == n+1 || getmax(1, 1, n, pos+1, r-1) >= a[pos]+d))
{
st.insert(pos);
}
}
if(l == 1 && r == n) Ans = (int)st.size() - 2;
return (int)st.size() - 2;
}
# | 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... |