This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+2;
int dist[N],n,subtask1;
vector<int> adj[N];
void init(int NP, std::vector<int> h) {
subtask1=is_sorted(begin(h),end(h));
n=NP;
set<int> spl;
vector<pair<int,int>> pp;
for(int j=0;j<n;j++)
pp.push_back({h[j],j});
sort(begin(pp),end(pp));
for(int j=n-1;j>=0;j--)
{
auto it = spl.upper_bound(pp[j].second);
if(it!=end(spl))
adj[pp[j].second].push_back(*it);
if(it!=begin(spl))
adj[pp[j].second].push_back(*(--it));
spl.insert(pp[j].second);
}
}
int minimum_jumps(int a, int b, int c, int d) {
if(subtask1)
return max(0,c-b);
for(int j=0;j<=n;j++)
dist[j]=2e9;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
for(int st=a;st<=b;st++)
pq.push({dist[st]=0,st});
while(pq.size())
{
auto it=pq.top();
if(c<=it.second and it.second<=d)
return it.first;
pq.pop();
if(dist[it.second]==it.first)
for(auto dj:adj[it.second])
if(dist[dj]>(dist[it.second]+1))
pq.push({dist[dj]=dist[it.second]+1,dj});
}
return -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... |