Under construction

Still being built. Things may change

MountainCraft

Time limit5sMemory limit2048 MB

Summary
After each toggle of a mountain peak, the task is to print the total length of the visible skyline edges (the upper envelope of the triangles) within the viewport [0, w].
Level

Hard9 of 10

Topics
Segment tree, Geometry, Implementation
Solved
No attempts yet

Statement

It is a glorious day in MountainCraft, a video game meta-world with an expansive open world full of mountains to explore. Your avatar wakes up on a remote island and stares at the mountains on the horizon.

The horizon is modeled as a Cartesian plane, with the xx-axis (y=0y = 0) separating land from sea. Each mountain peak is a point (x,y)(x, y). 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 that lie in the viewport. The visible edges of the mountains, where they do not overlap other mountains, are rendered in bold. Where 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 input after all mountains appear.

Due to graphical glitches, mountains can appear and disappear. After each change, output the total length of all bold lines currently visible in the viewport.

Input

The first line 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 visible mountain, that mountain disappears. Otherwise, that mountain appears.

Output

Output qq lines. For each query, in order, output one number: the total length of the bold lines rendered. Your answer is accepted if its absolute or relative error is within 10−610^{-6} of the judge's answer.

Hint

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.

Examples2

  1. Example 1

    Input
    3 10
    3 2
    7 3
    9 6
    
    Expected output
    5.656854
    12.727922
    12.727922
    
  2. Example 2

    Input
    5 100
    31 41
    59 26
    31 41
    59 26
    31 41
    
    Expected output
    101.823376
    120.208153
    73.539105
    0.000000
    101.823376