Submission #1052127

#TimeUsernameProblemLanguageResultExecution timeMemory
1052127PiokemonRainforest Jumps (APIO21_jumps)C++17
33 / 100
4085 ms8096 KiB
#include "jumps.h" #include <bits/stdc++.h> using namespace std; typedef long long int ll; constexpr int N = 2e5; int h[N+9]; int l[N+9]; int r[N+9]; int dst[N+9]; int n; constexpr int base = (1<<18); int tree[2*base+9]; // min void sed(int x, int a, int b, int p, int k, int val){ if (b<p || k<a)return; if (p<=a && b<=k){ tree[x]=min(tree[x],val); return; } int mid=(a+b)/2; sed(2*x,a,mid,p,k,val); sed(2*x+1,mid+1,b,p,k,val); } int query(int x){ x+=base; int odp=1e9; while(x){ odp=min(odp,tree[x]); x/=2; } return odp; } void init(int N, std::vector<int> H) { n=N; for (int x=0;x<n;x++)h[x]=H[x]; for (int x=0;x<=2*base+2;x++)tree[x]=1e9; for (int x=n-1;x>=0;x--){ r[x]=query(h[x]); sed(1,0,base-1,0,h[x],x); } for (int x=0;x<=2*base+2;x++)tree[x]=1e9; for (int x=0;x<n;x++){ l[x]=-query(h[x]); sed(1,0,base-1,0,h[x],-x); } /*for (int x=0;x<n;x++){ cerr << l[x] << ' ' << r[x] << '\n'; }*/ return; } int minimum_jumps(int A, int B, int C, int D){ vector<int> kol; for (int x=0;x<n;x++)dst[x]=1e9; for (int x=A;x<=B;x++){ dst[x]=0; kol.push_back(x); } for (int y=0;y<(int)kol.size();y++){ if (C<=kol[y] && kol[y]<=D)return dst[kol[y]]; if (l[kol[y]]!=-1e9){ if (dst[l[kol[y]]]>dst[kol[y]]+1){ dst[l[kol[y]]]=dst[kol[y]]+1; kol.push_back(l[kol[y]]); } } if (r[kol[y]]!=1e9){ if (dst[r[kol[y]]]>dst[kol[y]]+1){ dst[r[kol[y]]]=dst[kol[y]]+1; kol.push_back(r[kol[y]]); } } } return -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...