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<bits/stdc++.h>
#include "jumps.h"
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=2e5+10;
const int SS=1<<19;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=913;
const int L=18;
int t[N],l[N][L+1],r[N][L+1],n;
void init(int nn,vi v){
n=nn;
for(int i=1;i<=n;i++) t[i]=v[i-1];
deque<pair<int,int> >deq;
for(int i=n;i>=1;i--){
while(deq.size() and deq.back().fi<t[i]) deq.pop_back();
if(!deq.size()) r[i][0]=n+1;
else r[i][0]=deq.back().se;
deq.push_back({t[i],i});
}
deq.clear();
for(int i=1;i<=n;i++){
while(deq.size() and deq.back().fi<t[i]) deq.pop_back();
if(!deq.size()) l[i][0]=0;
else l[i][0]=deq.back().se;
deq.push_back({t[i],i});
}
for(int i=0;i<=L;i++) r[n+1][i]=n+1;
for(int i=1;i<=n;i++){
for(int k=1;k<=L;k++) l[i][k]=l[l[i][k-1]][k-1];
}
for(int i=n;i>=1;i--){
for(int k=1;k<=L;k++) r[i][k]=r[r[i][k-1]][k-1];
}
}
int minimum_jumps(int a,int b,int c,int d){
a++,b++,c++,d++;
int cc=c;
for(int i=L;i>=0;i--) if(r[cc][i]<=d) cc=r[cc][i];
if(t[b]>t[cc]) return -1;
int bb=b;
for(int i=L;i>=0;i--) if(l[bb][i]>=a and t[l[bb][i]]<t[cc]) bb=l[bb][i];
int res=-1,curr=0;
for(int i=L;i>=0;i--){
if(r[bb][i]<c) curr+=(1<<i),bb=r[bb][i];
else res=curr+(1<<i);
}
return res;
}
# | 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... |