Segments

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

요약
각 질의 x = p에 대해 모든 선분이 이 수직선과 만나도록 늘려야 하는 가로 거리 중 최댓값을 구한다.
난이도

보통10점 중 7점

유형
누적 합, 정렬, 배열, 구현
정답자
아직 제출이 없습니다

문제

In the first quadrant of a coordinate plane, you are given nn line segments parallel to the xx-axis. Each segment S_iS\_i (1≤i≤n1 ≤ i ≤ n) is represented by the coordinates of its left and right endpoints, (l_i,y_i)(l\_i , y\_i ) and (r_i,y_i)(r\_i , y\_i ), respectively. All coordinates are positive integers.

You must now answer qq queries. For each query, a vertical line x=px = p, parallel to the yy-axis, is given. The vertical line is represented by a single positive integer pp.

If each segment S_iS\_i is horizontally extended, it will eventually meet the line x=px = p at the point (p,y_i)(p, y\_i ). If the segment, including its endpoints, already meets x=px = p, no extension is needed. For example, suppose there are 55 segments (2,3),(5,3)\\{(2, 3), (5, 3)\\}, (4,6),(9,6)\\{(4, 6), (9, 6)\\}, (8,2),(12,2)\\{(8, 2), (12, 2)\\}, (11,4),(13,4)\\{(11, 4), (13, 4)\\}, and (14,5),(17,5)\\{(14, 5), (17, 5)\\}, and a single line x=11x = 11. The first segment must be extended by 66 to the right, the second segment 22 to the right, the third and the fourth segments 00, and the fifth segment 33 to the left for each to meet x=11x = 11.

For each query, determine the maximum among the extension lengths required for all segments to meet the line x=px = p. Formally, let dist(p,S_i)\text{dist}(p, S\_i ) denote the distance that segment S_iS\_i must be extended to intersect x=px = p at (p,y_i)(p, y\_i ). For each query, output max⁡_1≤i≤ndist(p,S_i)\max\_{1≤i≤n}{\text{dist}(p, S\_i )}. In the example above, the answer to the query is 66. See the figure below.

Given nn segments and qq queries, write a program to output the maximum extension length for each query.

입력

Your program is to read from standard input. The input starts with a line containing two integers nn (1≤n≤2×1061 ≤ n ≤ 2 \times 10^6) and qq (1≤q≤2×1061 ≤ q ≤ 2 \times 10^6), where nn is the number of line segments and qq is the number of queries. In the following nn lines, the ii-th line contains three integers, l_il\_i, r_ir\_i, and y_iy\_i (1≤l_i≤r_i≤1091 ≤ l\_i ≤ r\_i ≤ 10^9; 1≤y_i≤1031 ≤ y\_i ≤ 10^3), where l_il\_i (resp. r_ir\_i) is the xx-coordinate of left (resp. right) endpoint of S_iS\_i and y_iy\_i is the yy-coordinate of both endpoints of S_iS\_i. In the following qq lines of queries, the jj-th line contains one integer p_jp\_j (1≤p_j≤1091 ≤ p\_j ≤ 10^9) which denotes the vertical line x=p_jx = p\_j.

출력

Your program is to write to standard output. Print exactly one line per each query. The jj-th line should contain the maximum among the extension lengths required for all segments to meet x=p_jx = p\_j at (p_j,y_j)(p\_j , y\_j).

예제2

  1. 예제 1

    입력
    5 3
    2 5 3
    4 9 6
    8 12 2
    11 13 4
    14 17 5
    11
    5
    1
    
    예상 출력
    6
    9
    13
    
  2. 예제 2

    입력
    4 8
    1 4 7
    3 7 5
    10 13 8
    12 15 2
    13
    7
    4
    8
    3
    11
    1
    16
    
    예상 출력
    9
    5
    8
    4
    9
    7
    11
    12