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>
using namespace std;
/*
se eu tenho um cara da esquerda sempre vale pegar primeiro cara que der da direita
se eu tenho um destino na direita sempre vale pegar o maior cara da esquerda q chega la
nenhuma subtituição nos intervalos muda nada pq
*/
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
const int MAXN = 2e5+10, MAXQ = 1e5+10, BIG = 1e9+8;
int n, h[MAXN], ds[MAXN];
bool thing = 0;
void init(int N, vector<int> H){
n = N;
thing = 1;
for (int i=0;i<n;i++){
h[i] = H[i];
if (h[i]!=i+1) thing=0;
}
}
int minimum_jumps(int A, int B, int C, int D){ // A <= B < C <= D
if (thing){
return C-B;
}
vector<int> ps(n+1, 0);
for (int i=A;i<=D;i++) ps[h[i]]++;
for (int i=1;i<=n;i++) ps[i] += ps[i-1];
// vector<int> lf, rg;
// for (int i=A;i<=B;i++) lf.push_back(h[i]);
// for (int i=C;i<=D;i++) rg.push_back(h[i]);
// sort(lf.begin(), lf.end());
// sort(rg.begin(), rg.end());
// int i=0, ans = BIG;
// for (int j=0;j<rg.size();j++){
// while (i+1<lf.size() && lf[i+1]<rg[j]) i++;
// if (lf[i]<rg[j]){
// int cst = ps[rg[j]]-ps[lf[i]];
// if (cst<ans) ans = cst;
// }
// }
int ans = BIG;
for (int i=A;i<=B;i++){
for (int j=C;j<=D;j++) if(h[j]>h[i]){
ans = min(ans, ps[h[j]]-ps[h[i]]);
}
}
if (ans==BIG) return -1;
return ans;
}
# | 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... |