Highest

시간 제한5초메모리 제한2048 MB

요약
각 질의 (A,B)마다 1의 비용으로 v[i]층까지, 2의 비용으로 w[i]층까지 오를 수 있을 때 A층에서 B층까지 가는 최소 비용을 구한다.
난이도

보통10점 중 5점

유형
그래프, 최단 경로, 그리디
정답자
아직 제출이 없습니다

문제

In an alternate universe, Vlad is stuck inside a futuristic version of the Poenari Fortress, now spanning nn floors, numbered 00 through n−1n − 1. From each floor ii (0≤i≤n−10 ≤ i ≤ n − 1), he can only go up, either by taking the stairs and paying 11 drop of blood (this is the currency that vampires use to pay in Romania), or by turning into a bat and traversing the vents, for which he has to pay 22 drops of blood. The stairs can take him up to v\[i]v\[i] floors upwards, while the vents span up to w\[i]w\[i] floors upwards, where vv and ww are two given arrays: v=v\[0],v\[1],…,v\[n−1]v = v\[0], v\[1], \dots , v\[n − 1] and w=w\[0],w\[1],…,w\[n−1]w = w\[0],w\[1], \dots ,w\[n − 1].

Formally, from floor ii (0≤i≤n−10 ≤ i ≤ n − 1), Vlad can go:

  • anywhere from floor i+1i + 1 to floor i+v\[i]i + v\[i] without exceeding n−1n − 1, for a cost of 11
  • anywhere from floor i+1i + 1 to floor i+w\[i]i + w\[i] without exceeding n−1n − 1, for a cost of 22

Furthermore, his brothers Radu and Mircea proposed mm scenarios for Vlad, each one consisting of two floors AA and BB (A≤BA ≤ B). Vlad has to answer their mm questions: what is the least amount of blood that he has to sacrifice to get from floor AA to floor BB?

제한

  • 1≤n,m≤500,0001 ≤ n,m ≤ 500\\, 000.
  • 1≤v\[i],w\[i]≤n1 ≤ v\[i],w\[i] ≤ n for all 0≤i≤n−10 ≤ i ≤ n − 1.
  • 0≤A≤B≤n−10 ≤ A ≤ B ≤ n − 1 for all queries.

예제

이 문제는 공개된 예제가 없습니다.