MountainCraft

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

요약
질의마다 산이 나타나거나 사라질 때, 뷰포트 안에서 다른 산과 겹치지 않아 굵게 그려지는 능선의 총 길이를 1e-6 오차로 구한다.
난이도

어려움10점 중 8점

유형
기하, 세그먼트 트리, 수학, 구현
정답자
아직 제출이 없습니다

문제

It's a glorious day in the video game meta-world of MountainCraft! True to its name, MountainCraft boasts an expansive open world full of mountains to explore. Your avatar in the game wakes up on a remote island, and stares at the mountains on the horizon.

The view of the horizon can be modeled as a Cartesian plane, with the xx-axis (y=0y = 0) separating land from sea. Each mountain peak is represented by a point (x,y)(x, y), and the mountain's sides have slope +1+1 and −1-1, forming a triangle with that peak at the top.

Your avatar can only see the parts of the mountains which are in a viewport. The visible edges of the mountains, where they do not overlap other mountains, are rendered in bold. If mountains overlap, the overlapping parts are not rendered in bold. Edges do not have to intersect for mountains to overlap.

Figure H.1: The first sample input after all mountains appear.

Unfortunately, due to graphical glitches, mountains can appear and disappear. After each change, you want to know the total length of all the bold lines currently visible in the viewport.

입력

The first line of input contains two integers qq (1≤q≤2⋅1051 \leq q \leq 2 \cdot 10^{5}) and ww (1≤w≤1091 \leq w \leq 10^9), where qq is the number of queries and ww is the width of the viewport. The viewport stretches from 00 to ww.

Each of the next qq lines contains two integers xx (0≤x≤w0 \leq x \leq w) and yy (0<y≤1090 < y \leq 10^{9}), the peak of some mountain. If (x,y)(x, y) is the peak of a mountain that is visible, that mountain will disappear. Otherwise, that mountain will become visible.

출력

Output qq lines. For each query in order, output a single line with a single number, which is the total length of the bold lines rendered. Your answer will be accepted if the absolute or relative error is within 10−610^{-6} of the judge's answer.

힌트

In the first sample, the first two mountains intersect at the point (4.5,0.5)(4.5, 0.5) The parts of the mountains below that point are not rendered in bold.

In the second sample, the left mountain appears, then disappears, then appears again. The right mountain appears and then disappears.

예제2

  1. 예제 1

    입력
    3 10
    3 2
    7 3
    9 6
    
    예상 출력
    5.656854
    12.727922
    12.727922
    
  2. 예제 2

    입력
    5 100
    31 41
    59 26
    31 41
    59 26
    31 41
    
    예상 출력
    101.823376
    120.208153
    73.539105
    0.000000
    101.823376