Festival Decorating

면접 대비

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

요약
각 질의 거리 d마다 x_u+d 위치에 다른 색 램프가 있는 가장 작은 램프 번호 u를 구한다.
난이도

어려움10점 중 8점

유형
배열, 정렬, 투 포인터
정답자
아직 제출이 없습니다

문제

To celebrate the coming winter festival in Byteland, the main street, which can be regarded as the x-axis, is decorated with nn colorful lamps, labeled by 1,2,…,n1, 2, \ldots, n. The x-coordinate of the ii-th lamp is x_ix\_i, and the color of the ii-th lamp is c_ic\_i. No two lamps share the same x-coordinate.

You will be given qq queries. In the ii-th query, you will be given an integer d_id\_i (1≤d_i≤250,0001 \leq d\_i \leq 250\\,000), and you need to find the lamp uu (1≤u≤n1 \leq u \leq n) with the minimum index such that there is another lamp located at x_u+d_ix\_u + d\_i and the color of that lamp is different from c_uc\_u, or determine it is impossible to find such uu. Your answer is considered correct if its absolute or relative error does not exceed 0.50.5.

입력

The first line of the input contains two integers nn and qq (1≤n,q≤250,0001 \leq n, q \leq 250\\,000) denoting the number of lamps and the number of queries.

Each of the next nn lines contains two integers x_ix\_i and c_ic\_i (1≤x_i≤250,0001 \leq x\_i \leq 250\\,000, 1≤c_i≤n1 \leq c\_i \leq n) denoting the x-coordinate and the color of the ii-th lamp. It is guaranteed that no two lamps share the same x-coordinate.

Each of the next qq lines contains a single integer d_id\_i (1≤d_i≤250,0001 \leq d\_i \leq 250\\,000) denoting the ii-th query.

출력

For each query, print a line containing a single number: the minimum index uu you found. If it is impossible to find such uu, print 00 instead.

Your answer is considered correct if its absolute or relative error does not exceed 0.50.5. Note that this means you can output a non-integer as well.

Formally, let your answer be uu, and the jury's answer be u′u'. Your answer is accepted if and only if: ∣u−u′∣max⁡(1,∣u′∣)≤0.5.\frac{|u - u'|}{\max(1, |u'|)} \le 0.5\text{.}

예제1

  1. 예제 1

    입력
    4 5
    3 1
    1 2
    5 1
    6 2
    1
    2
    3
    4
    5
    
    예상 출력
    3
    2
    1
    2
    0