아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Sky Walking

시간 제한4초메모리 제한1024 MB

요약
건물은 수직 선분, 하늘길은 수평 선분일 때 두 건물 바닥 사이의 최단 경로 길이를 구한다.
난이도

보통10점 중 7점

유형
그래프, 최단 경로, 정렬, 이분 탐색
정답자
아직 제출이 없습니다

문제

Kenan drew a plan of the buildings and skywalks along one side of the main avenue of Baku. There are nn buildings numbered from 00 to n−1n-1 and mm skywalks numbered from 00 to m−1m-1. The plan is drawn on a two-dimensional plane, where the buildings and skywalks are vertical and horizontal segments respectively.

The bottom of building ii (0≤i≤n−1)(0 \leq i \leq n-1) is located at point (x\[i],0)(x\[i], 0) and the building has height h\[i]h\[i]. Hence, it is a segment connecting the points (x\[i],0)(x\[i], 0) and (x\[i],h\[i])(x\[i], h\[i]).

Skywalk jj (0≤j≤m−1)(0 \leq j \leq m-1) has endpoints at buildings numbered l\[j]l\[j] and r\[j]r\[j] and has a positive yy-coordinate y\[j]y\[j]. Hence, it is a segment connecting the points (x\[l\[j]],y\[j])(x\[l\[j]], y\[j]) and (x\[r\[j]],y\[j])(x\[r\[j]], y\[j]).

A skywalk and a building intersect if they share a common point. Hence, a skywalk intersects two buildings at its two endpoints, and may also intersect other buildings in between.

Kenan would like to find the length of the shortest path from the bottom of building ss to the bottom of building gg, assuming that one can only walk along the buildings and skywalks, or determine that no such path exists. Note that it is not allowed to walk on the ground, i.e. along the horizontal line with yy-coordinate 00.

One can walk from a skywalk into a building or vice versa at any intersection. If the endpoints of two skywalks are at the same point, one can walk from one skywalk to the other.

Your task is to help Kenan answer his question.

제한

  • 1≤n,m≤100,0001 \leq n, m \leq 100\\,000
  • 0≤x\[0]<x\[1]<…<x\[n−1]≤1090 \leq x\[0] < x\[1] < \ldots < x\[n - 1] \leq 10^9
  • 1≤h\[i]≤1091 \leq h\[i] \leq 10^9 (for all 0≤i≤n−10 \leq i \leq n-1)
  • 0≤l\[j]<r\[j]≤n−10 \leq l\[j] < r\[j] \leq n-1 (for all 0≤j≤m−10 \leq j \leq m-1)
  • 1≤y\[j]≤min⁡(h\[l\[j]],h\[r\[j]])1 \leq y\[j] \leq \min(h\[l\[j]], h\[r\[j]]) (for all 0≤j≤m−10 \leq j \leq m-1)
  • 0≤s,g≤n−10 \leq s, g \leq n - 1
  • s≠gs \neq g
  • No two skywalks have a common point, except maybe on their endpoints.

예제

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