이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int ml[N],mr[N];
int best[N];
int arr[N];
const int inf = 1e9;
int MAXN;
bool one = true;
void init(int n,vector<int> a){
for(int i = 1;i<=n;i++){
ml[i] = 0;
mr[i] = n + 1;
arr[i] = a[i - 1];
one &= (arr[i] == i);
}
MAXN = n;
arr[0] = arr[n + 1] = inf;
stack<int> lg;
for(int i = 1;i<=n;i++){
while(lg.size() > 0 && arr[lg.top()] <= arr[i]) lg.pop();
if(lg.size() > 0){
ml[i] = lg.top();
}
lg.push(i);
}
stack<int> rg;
for(int i = n;i >= 1;i--){
while(rg.size() > 0 && arr[rg.top()] <= arr[i]) rg.pop();
if(rg.size() > 0){
mr[i] = rg.top();
}
rg.push(i);
}
for(int i = 1;i<=n;i++){
best[i] = (arr[ml[i]] > arr[mr[i]] ? ml[i] : mr[i]);
}
}
int minimum_jumps(int a,int b,int c,int d){
a ++,b ++;
c ++,d ++;
// if(one) return c - b;
int m2 = c;
for(int i = c + 1;i <= d;i ++){
if(arr[i] > arr[m2]) m2 = i;
}
int maxi = -1;
int m1 = a;
for(int i = a;i <= b;i++){
if(arr[i] > maxi && arr[i] < arr[m2]){
maxi = arr[i];
m1 = i;
}
}
if(maxi == -1) return -1;
int x = m1;
int ans = 0;
while (true) {
int u=best[x];
// if (u < c && rh[u] < c && h[u] < mxv) x=u, ans+=(1<<j);
if(u < c && mr[x] < c && arr[u] < arr[m2]){
x = u;
ans +=1;
}else{
break;
}
}
// if (up[0][x] < c && h[up[0][x]] < mxv && rh[x] < c) x=up[0][x], ++ans;
while(true) {
int u=mr[x];
if (u < c) x=u, ans+=1;
else break;
}
if (mr[x] >= c && mr[x] <= d) return ans+1;
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... |