PivotOJ

Sky Walking

시간 제한: 4000ms메모리 제한: 1024MB출처: IOI 2019BOJ 19928

문제

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 n1n-1 and mm skywalks numbered from 00 to m1m-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 (0in1)(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 (0jm1)(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.

코드를 제출하려면 로그인하세요.