제출 #983063

#제출 시각아이디문제언어결과실행 시간메모리
983063vjudge1밀림 점프 (APIO21_jumps)C++17
100 / 100
866 ms63952 KiB
#include "jumps.h" #include <bits/stdc++.h> using namespace std; vector<int>adj[200100]; int vis[200100],d[200100],n,h[200100],rbj[200100][20],obj[200100][20],st[200100][20],loc[200100]; vector<int> v; int query(int a,int b){ int x=31-__builtin_clz(b-a+1); return max(st[a][x],st[b-(1<<x)+1][x]); } void init(int N, std::vector<int> H) { stack<int> stk; for(int i=0;i<N;i++) loc[st[i+1][0]=h[i+1]=H[i]]=i+1; h[0]=1e9,n=N; for(int j=1;j<20;j++) for(int i=1;i+(1<<j)-2<n;i++) st[i][j]=max(st[i][j-1],st[i+(1<<j-1)][j-1]); for(int i=0;i<N;i++){ while(stk.size()&&H[stk.top()]<=H[i]) stk.pop(); if(stk.size()) adj[i+1].push_back(stk.top()+1); stk.push(i); } while(stk.size())stk.pop(); for(int i=N;i--;){ while(stk.size()&&H[stk.top()]<=H[i]) stk.pop(); if(stk.size()) adj[i+1].push_back(rbj[i+1][0]=stk.top()+1); stk.push(i); } for(int i=1;i<=N;i++)if(adj[i].size()>1) obj[i][0]=adj[i][h[adj[i][0]]<=h[adj[i][1]]]; else if(adj[i].size()) obj[i][0]=adj[i][0]; for(int j=1;j<20;j++) for(int i=1;i<=N;i++) rbj[i][j]=rbj[rbj[i][j-1]][j-1], obj[i][j]=obj[obj[i][j-1]][j-1]; } int calc(int a,int b,int c,int d){ int ans=0; for(int i=20;i--;) if(h[obj[a][i]]<=c) a=obj[a][i],ans+=1<<i; if(h[obj[a][0]]<=d) return ans+1+(obj[a][0]<b&&rbj[a][0]<b); for(int i=20;i--;) if(rbj[a][i]<b&&rbj[a][i]) a=rbj[a][i],ans+=1<<i; return ans+1; } int minimum_jumps(int A, int B, int C, int D) { A++,B++,C++,D++; int m1=query(B,C-1),m2=query(C,D); if(m1>m2) return -1; int l=A,r=B; while(l<=r){ int mid=l+r>>1; if(query(mid,B)<m2) A=mid,r=mid-1; else l=mid+1; } return calc(loc[query(A,B)],C,m1,m2); }

컴파일 시 표준 에러 (stderr) 메시지

jumps.cpp: In function 'void init(int, std::vector<int>)':
jumps.cpp:17:43: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   17 |         st[i][j]=max(st[i][j-1],st[i+(1<<j-1)][j-1]);
      |                                          ~^~
jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:60:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |         int mid=l+r>>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...