Building a wall

Let us use right trapezoids to build a wall. Each trapezoid is defined by four real parameters \ell, rr, yy_\ell and yry_r, which indicate the points (,0)(\ell, 0), (,y)(\ell, y_\ell), (r,yr)(r, y_r), and (r,0)(r, 0). For instance, adding the trapezoids (1 5 1 3) and (7 11 1 3) into an empty wall produces the figure to the left:

(13,8) (0,1)(13,1) (1,0)(1,7) (2,0)1 (3,0)2 (4,0)3 (5,0)4 (6,0)5 (7,0)6 (8,0)7 (9,0)8 (10,0)9 (11,0)10 (12,0)11 (0,2)1 (0,3)2 (0,4)3 (0,5)4 (0,6)5 (2,1)(2,2) (2,2)(6,4) (6,4)(6,1) (8,1)(8,2) (8,2)(12,4) (12,4)(12,1)

(13,8) (0,1)(13,1) (1,0)(1,7) (2,0)1 (3,0)2 (4,0)3 (5,0)4 (6,0)5 (7,0)6 (8,0)7 (9,0)8 (10,0)9 (11,0)10 (12,0)11 (0,2)1 (0,3)2 (0,4)3 (0,5)4 (0,6)5 (2,1)(2,2) (2,2)(4,3) (4,3)(4,6) (4,6)(6,6) (6,6)(6,3) (6,3)(8,2) (8,2)(8,3) (8,3)(10,3) (10,3)(12,4) (12,4)(12,1)

The material of the trapezoids is semifluid, so they adapt to the shape underneath. For instance, adding (3 9 3 0) to the figure to the left produces the figure to the right. Write a program to keep track of the shape of an initially empty wall, with two kind of operations:

Input

Input consists of several cases, each one with the number of operations nn, followed by those operations. Assume 1n1051 \le n \le 10^5, that all given parametres are real numbers between 0 and 10410^4, <r\ell < r, and that every xx is different to all previous \ell and rr.

Output

For every ‘C’ operation, print the height at xx with three digits after the decimal point. The input cases do not have precision issues.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T10:33:22.027Z

© Jutge.org, 2006–2026.
https://jutge.org