PivotOJ

Flappy Bird

시간 제한: 1750ms메모리 제한: 1024MB출처: GCPC 2021BOJ 25250

문제

Help the bird Faby to navigate through a sequence of nn pairs of pipes, by finding the shortest line he can fly on to reach his destination. For simplicity, we represent Faby as a single point in the plane and assume every pipe has width zero. This way, the gap between every pair of pipes can be represented as an interval on the yy axis. The bird starts out at s=(xs,ys)s = (x_s, y_s) and his goal is to reach t=(xt,yt)t = (x_t, y_t). Find the shortest line from ss to tt, passing through all intervals in between in increasing order of their xx coordinates.

Figure F.1: Visualisation of the second sample input. The red lines represent the intervals and the black line the shortest possible path. Faby and the black dots are the points in the output. Note that (2,1)(2, 1) can optionally be included in the output too.

입력

The input consists of:

  • One line with four integers xs,ys,xtx_s, y_s, x_t and yty_t (109xs,ys,xt,yt109-10^9 \le x_s, y_s, x_t, y_t \le 10^9), the start and end points.
  • One line with an integer n (0n106)n\ (0 \le n \le 10^6), the number of intervals.
  • nn lines, the iith of which contains three integer xi,yi,1x_i, y_{i,1} and yi,2y_{i,2} (109xi,yi,1,yi,2109-10^9 \le x_i, y_{i, 1}, y_{i, 2} \le 10^9, yi,1<yi,2y_{i, 1} < y_{i, 2}), the intervals.

It can be assumed that xs<x1<<xn<xtx_s < x_1 < \dots < x_n < x_t.

출력

Output a sequence of kk (2kn+2(2 \le k \le n+2) points p1,,pkp_1, \dots, p_k, one per line, such that:

  • All points have integer coordinates.
  • p1=sp_1 = s and pk=tp_k = t.
  • Let PP be the path obtained by connecting pipi+1\overline{p_i p_{i+1}} for all 1i<k1 \le i < k. Then:
    • PP passes through all intervals in increasing order of their xx coordinates.
    • The length of PP is minimal.

If there are multiple valid solutions, you may output any one of them.

예제

예제 1

입력
0 0 10 0
1
5 -10 10
출력
0 0
10 0

예제 2

입력
0 0 10 0
4
2 1 3
4 2 3
7 0 2
9 -2 -1
출력
0 0
4 2
9 -1
10 0
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.