MountainCraft
시간 제한5초메모리 제한2048 MB
질의마다 산이 나타나거나 사라질 때, 뷰포트 안에서 다른 산과 겹치지 않아 굵게 그려지는 능선의 총 길이를 1e-6 오차로 구한다.
문제
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 -axis () separating land from sea. Each mountain peak is represented by a point , and the mountain's sides have slope and , 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 () and (), where is the number of queries and is the width of the viewport. The viewport stretches from to .
Each of the next lines contains two integers () and (), the peak of some mountain. If is the peak of a mountain that is visible, that mountain will disappear. Otherwise, that mountain will become visible.
출력
Output 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 of the judge's answer.
힌트
In the first sample, the first two mountains intersect at the point 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.