이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> H;
int unde[200005];
const int INF = 1e9;
int parent[200005];
int tole[200005],tori[200005];
void init(int N, std::vector<int> copH)
{
H=copH;
deque<int> dq;
for(int i=0;i<N;i++)
{
unde[H[i]]=i;
while(!dq.empty() && H[dq.back()] < H[i])
dq.pop_back();
if(dq.empty())
tole[i]=-1;
else
tole[i]=dq.back();
dq.push_back(i);
}
dq.clear();
for(int i=N-1;i>=0;i--)
{
while(!dq.empty() && H[dq.back()] < H[i])
dq.pop_back();
if(dq.empty())
tori[i]=N;
else
tori[i]=dq.back();
dq.push_back(i);
}
}
int getmax(int le, int ri)
{
int mxm=0;
for(int i=le;i<=ri;i++)
mxm = max(mxm, H[i]);
return mxm;
}
int getdist(int cur, int le, int ri)
{
int pasi=0,mxm=getmax(le,ri);
while(1)
{
if(tori[cur]>ri || H[cur] > mxm)
return INF;
if(tori[cur]>=le && tori[cur]<=ri)
return pasi+1;
if(H[tole[cur]] > H[tori[cur]] && H[tole[cur]] < mxm)
{
cur = tole[cur];
}
else
{
cur = tori[cur];
}
pasi++;
}
return pasi;
}
int minimum_jumps(int A, int B, int C, int D)
{
if(getmax(B+1,C-1) > getmax(C,D))
return -1;
if(H[B] > getmax(C,D))
return -1;
int st=A,dr=B,primu=-1;
while(st<=dr)
{
int mij=(st+dr)/2;
if(getmax(mij,B) < getmax(C,D))
{
primu=unde[getmax(mij,B)];
dr=mij-1;
}
else
{
st=mij+1;
}
}
/**for(int i=A;i<=B;i++)
{
if(getmax(i,B) < getmax(C,D))
{
primu=unde[getmax(i,B)];
break;
}
}*/
if(primu==-1)
return -1;
else
return getdist(primu,C,D);
}
# | 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... |