제출 #984002

#제출 시각아이디문제언어결과실행 시간메모리
984002Nexus밀림 점프 (APIO21_jumps)C++17
0 / 100
4101 ms22616 KiB
#include <bits/stdc++.h> #define ll long long #define mid (r+l)/2 using namespace std; const ll N=2e5+9,M=2e18+9,mod=1e9+7; bool vis[N]; pair<ll,ll>p; vector<ll>v[N]; ll t[4*N],n,x,y,z; queue<pair<ll,ll>>q; void up(ll i,ll l,ll r,ll ind,ll v,bool ty) { if(l==r) { t[i]=v; return; } if(ind<=mid)up(2*i,l,mid,ind,v,ty); else up(2*i+1,mid+1,r,ind,v,ty); if(ty)t[i]=max(t[2*i],t[2*i+1]); else t[i]=min(t[2*i],t[2*i+1]); } ll Q(ll i,ll l,ll r,ll s,ll e,bool ty) { if(s<=l && r<=e)return t[i]; if(s<=mid && mid<e) { if(ty)return max(Q(2*i,l,mid,s,e,ty),Q(2*i+1,mid+1,r,s,e,ty)); else return min(Q(2*i,l,mid,s,e,ty),Q(2*i+1,mid+1,r,s,e,ty)); } if(s<=mid)return Q(2*i,l,mid,s,e,ty); return Q(2*i+1,mid+1,r,s,e,ty); } void init(int n,vector<int>h) { memset(t,0,sizeof t); for(ll i=0;i<n;++i) { up(1,0,n,h[i],i+1,1); x=(h[i]<n?Q(1,0,n,h[i]+1,n,1):0); if(x)v[x-1].push_back(i); } for(ll i=0;i<4*N;++i)t[i]=M; for(ll i=n-1;i>=0;--i) { up(1,0,n,h[i],i+1,0); x=(h[i]<n?Q(1,0,n,h[i]+1,n,0):0); if(x)v[x-1].push_back(i); } } int minimum_jumps(int A, int B, int C, int D) { x=-1; memset(vis,false,sizeof vis); for(ll i=C;i<=D;++i) for(auto j:v[i])q.push({j,1}); while(q.size()) { p=q.front(); q.pop(); if(vis[p.first])continue; vis[p.first]=1; if(A<=p.first && p.first<=B) x=(x==-1?p.second:min(x,p.second)); ++p.second; for(auto j:v[p.first])q.push({j,p.second}); } return x; }
#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...