아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Good Night

시간 제한6초메모리 제한1024 MB

요약
각 가로등은 A_i부터 주기 T마다 켜지고 꺼지며, Azber가 도달할 수 있는 한 계속 켜둘 수 있는지와 영구히 꺼진 경우 마지막으로 켜져 있던 시각을 구한다.
난이도

보통10점 중 7점

유형
시뮬레이션, 정렬, 구현
정답자
아직 제출이 없습니다

문제

There are NN streetlights on a straight road. The road can be represented as a number line. ii-th streetlight is located at X_iX\_{i} and illuminates \[L_i,R_i]\[L\_{i}, R\_{i}] (X_i>0X\_{i} > 0). Initially, at the time 00, every streetlights are on. At time A_iA\_i, ii-th streetlight goes out. After every time TT, if iith streetlight is on, it goes out. Precisely, ii-th streetlight is turned off if it is on at time A_i+kTA\_{i} + kT for all non-negative integer kk. (0<A_i≤T0 < A\_i \leq T)

Azber lives at the origin of the road, i.e. at coordinate 00. Azber is too scared to pass the point which is not illuminated by any streetlight. (Except for origin he lives) If Azber notices a turned-off streetlight that he can reach from the origin, he runs very fast and turns the streetlight back on. After he turns on a light, he directly comes back to the origin. The speed that Azber moves and lights up streetlights is so fast that the time Azber spent by movement can be ignored.

Over time, some streetlights goes out and is never turned on again. Our challenge is to figure out if each streetlight is permanently turned off. And for the lights which are turned off permanently, calculate the last time the light was on. Let's help timid Azber!

입력

Read the following data from the standard input. All the values in the input are integers.

NN TT

X_1X\_1 L_1L\_1 R_1R\_1 A_1A\_1

...

X_NX\_N L_NL\_N R_NR\_N A_NA\_N

출력

Print NN lines. For the ii-th line, if ii-th streetlight is not turned off permanently, i.e. for any t>0t>0 there exists t′>tt' > t such that the light is on at t′t', print −1-1. Otherwise, print the last time the light was turned on as an integer.

제한

  • 1≤N≤3000001 \leq N \leq 300000
  • 1≤T≤1091 \leq T \leq 10^9
  • 0≤L_i<R_i≤1090 \leq L\_i < R\_i \leq 10^9
  • 0<X_i≤1090 < X\_i \leq 10^9
  • 0<A_i≤T0 < A\_i \leq T

예제4

  1. 예제 1

    입력
    4 10
    5 0 4 3
    2 0 3 1
    7 2 6 9
    3 7 8 4
    
    예상 출력
    13
    21
    9
    24
    
  2. 예제 2

    입력
    4 10
    3 4 5 5
    7 0 4 6
    5 0 6 5
    8 0 7 7
    
    예상 출력
    25
    16
    25
    7
    
  3. 예제 3

    입력
    2 7
    2 0 5 3
    3 0 2 4
    
    예상 출력
    -1
    -1
    
  4. 예제 4

    입력
    8 1000
    3 0 4 17
    6 0 7 9
    8 5 9 14
    11 1 12 7
    15 2 16 9
    17 13 18 5
    19 10 20 9
    21 14 22 13
    
    예상 출력
    1017
    1009
    1014
    1007
    9
    1005
    9
    13