이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
if(r[bb][0]>d) return -1;
return res;
}
/*int main(){
int n;
cin>>n;
vi xd;
for(int i=1;i<=n;i++){
int a;
cin>>a;
xd.push_back(a);
}
init(n,xd);
int q;
cin>>q;
while(q--){
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<minimum_jumps(a,b,c,d)<<"\n";
}
}*/
# | 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... |