이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 2e9+5
#define eps 1e-7
#define eps1 1e-25
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
#define V 450
using namespace std;
const int MOD = 1e9;
const int nax = 4e5+5;
const int lg = 30;
int nxt[nax][lg], mx[nax],bst[nax][lg];
void init(int n, vi h) {
stack<ii> st;
for (int i = n-1; i >= 0; --i)
{
while(!st.empty() && st.top().fi <= h[i]){
st.pop();
}
if(st.empty()) nxt[i][0] = INF;
else bst[i][0] = nxt[i][0] = st.top().se, mx[i] = st.top().fi;
st.push({h[i], i});
}
for (int i = 0; i < n; ++i)
{
while(!st.empty() && st.top().fi <= h[i]){
st.pop();
}
if(!st.empty() && mx[i] < st.top().fi) bst[i][0] = st.top().se;
st.push({h[i], i});
}
for (int i = 1; i < lg; ++i)
{
for (int j = 0; j < n; ++j)
{
if(nxt[j][i-1] == INF) nxt[j][i] = INF;
else nxt[j][i] = nxt[nxt[j][i-1]][i-1];
if(bst[j][i-1] == INF) bst[j][i] = INF;
else bst[j][i] = bst[bst[j][i-1]][i-1];
}
}
}
int minimum_jumps(int a, int b, int c, int d) {
int mn = INF;
for (int i = a; i <= b; ++i)
{
int cur = i, res = 0;
for (int j = lg-1; j >= 0; --j)
{
if(bst[cur][j] < c && nxt[cur][0] < c){
cur = bst[cur][j];
res += (1 << j);
}
}
if(nxt[cur][0] <= d){
mn = min(mn, res+1);
}
}
if(mn == INF) return -1;
return mn;
}
# | 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... |