Flappy Bird

아직 제출이 없습니다시간 제한1.75초메모리 제한1024 MB

문제

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=(x_s,y_s)s = (x\_s, y\_s) and his goal is to reach t=(x_t,y_t)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 x_s,y_s,x_tx\_s, y\_s, x\_t and y_ty\_t (109x_s,y_s,x_t,y_t109-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 x_i,y_i,1x\_i, y\_{i,1} and y_i,2y\_{i,2} (109x_i,y_i,1,y_i,2109-10^9 \le x\_i, y\_{i, 1}, y\_{i, 2} \le 10^9, y_i,1<y_i,2y\_{i, 1} < y\_{i, 2}), the intervals.

It can be assumed that x_s<x_1<<x_n<x_tx\_s < x\_1 < \dots < x\_n < x\_t.

출력

Output a sequence of kk (2kn+2(2 \le k \le n+2) points p_1,,p_kp\_1, \dots, p\_k, one per line, such that:

  • All points have integer coordinates.

  • p_1=sp\_1 = s and p_k=tp\_k = t.

  • Let PP be the path obtained by connecting p_ip_i+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.