Photo Op

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

요약
출발 시각마다 (X,0)에서 (0,Y)까지, 그 시각까지 나타난 선분들을 피하는 최단 경로의 길이를 구한다.
난이도

어려움10점 중 9점

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

문제

Farmer John's farm is full of lush vegetation and every cow wants a photo of its natural beauty. Unfortunately, Bessie still has places to be, but she doesn't want to disrupt any photo ops.

Bessie is currently standing at (X,0)(X,0) on the XY-plane and she wants to get to (0,Y)(0,Y) (1≤X,Y≤1061\le X,Y\le 10^6). Unfortunately, NN (1≤N≤3⋅1051 \leq N \leq 3 \cdot 10^5) other cows have decided to pose on the XX axis. More specifically, cow ii will be positioned at (x_i,0)(x\_i,0) with a photographer at (0,y_i)(0,y\_i) where (1≤x_i,y_i≤106)(1 \leq x\_i,y\_i \leq 10^6) ready to take their picture. They will begin posing moments before time s_is\_i (1≤s_i<T1 \leq s\_i < T) and they will keep posing for a very long time (they have to get their picture just right). Here, 1≤T≤N+11\le T\le N+1.

Bessie knows the schedule for every cow's photo op, and she will take the shortest Euclidean distance to get to her destination, without crossing the line of sight from any photographer to their respective cow (her path will consist of one or more line segments).

If Bessie leaves at time tt, she will avoid the line of sights for all photographer/cow pairs that started posing at time s_i≤ts\_i \le t, and let the distance to her final destination be d_td\_t. Determine the values of ⌊d_t⌋\lfloor d\_t\rfloor for each integer tt from 00 to T−1T-1 inclusive.

입력

The first line of input contains NN and TT, representing the number of cows posing on the xx-axis and the timeframe that Bessie could leave at.

The second line of input contains XX and YY, representing Bessie's starting XX coordinate and her target YY coordinate respectively.

The next NN lines contain s_is\_i x_ix\_i and y_iy\_i. It is guaranteed that all x_ix\_i are distinct from each other and XX, and all y_iy\_i are distinct from each other and YY. All s_is\_i will be given in increasing order, where s_i≤s_i+1s\_i \leq s\_{i+1}.

출력

Print TT lines, with the ttth (0-indexed) line containing ⌊d_t⌋\lfloor d\_t\rfloor.

예제3

  1. 예제 1

    입력
    4 5
    6 7
    1 7 5
    2 4 4
    3 1 6
    4 2 9
    
    예상 출력
    9
    9
    9
    10
    12
    
  2. 예제 2

    입력
    2 3
    10 7
    1 2 10
    1 9 1
    
    예상 출력
    12
    16
    16
    
  3. 예제 3

    입력
    5 6
    8 9
    1 3 5
    1 4 1
    3 10 7
    4 9 2
    5 6 6
    
    예상 출력
    12
    12
    12
    12
    14
    14