이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
const int nx=2e5+5, kx=18;
int l[kx][nx], r[kx][nx], g[kx][nx];
void init(int N, std::vector<int> H) {
H.push_back(INT_MIN);
stack<int> s;
for (int i=0; i<=N; i++) l[0][i]=r[0][i]=g[0][i]=N;
for (int i=0; i<N; i++)
{
while (!s.empty()&&H[s.top()]<H[i]) s.pop();
if (!s.empty()) l[0][i]=s.top();
s.push(i);
}
while (!s.empty()) s.pop();
for (int i=N-1; i>=0; i--)
{
while (!s.empty()&&H[s.top()]<H[i]) s.pop();
if (!s.empty()) r[0][i]=s.top();
s.push(i);
}
for (int i=0; i<N; i++) g[0][i]=(H[l[0][i]]>H[r[0][i]])?l[0][i]:r[0][i];
for (int i=1; i<kx; i++) for (int j=0; j<=N; j++) l[i][j]=l[i-1][l[i-1][j]], r[i][j]=r[i-1][r[i-1][j]], g[i][j]=g[i-1][g[i-1][j]];
}
int minimum_jumps(int A, int B, int C, int D) {
int opt=B, ans=0;
for (int i=kx-1; i>=0; i--) if (l[i][opt]>=A&&r[0][l[i][opt]]<=D) opt=l[i][opt];
if (C<=r[0][opt]&&r[0][opt]<=D) return 1;
for (int i=kx-1; i>=0; i--) if (r[0][g[i][opt]]<C) ans+=(1<<i), opt=g[i][opt];
if (r[0][g[0][opt]]<=D) return ans+2;
for (int i=kx-1; i>=0; i--) if (r[i][opt]<C) ans+=(1<<i), opt=r[i][opt];
if (r[0][opt]<C||r[0][opt]>D) return -1;
else return ans+1;
}
# | 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... |