QOJ.ac

QOJ

時間限制: 1.5 s 記憶體限制: 128 MB 總分: 100

#7464. Self Adjusting Top Tree

统计

There are $n$ line segments on a plane.

There are $m$ queries. Each query provides a rectangle with sides parallel to the coordinate axes. For each query, calculate the ratio of the sum of the lengths of the intersections between each line segment and the rectangle to the sum of the lengths of all line segments. The output must have a relative or absolute error not exceeding $10^{-6}$.

Line segments are given as $x_1\;y_1\;x_2\;y_2$, representing a segment with endpoints $(x_1, y_1)$ and $(x_2, y_2)$. It is guaranteed that no two line segments intersect or overlap, and $x_1 \neq x_2, y_1 \neq y_2$.

Rectangles are given as $x_1\;y_1\;x_2\;y_2$, representing the rectangle $\{(x, y) | x_1 \le x \le x_2, y_1 \le y \le y_2\}$. It is guaranteed that $x_1 < x_2$ and $y_1 < y_2$.

Input

The first line contains an integer $n$.

The next $n$ lines each contain four space-separated integers $x_1, y_1, x_2, y_2$, representing the line segments.

The next line contains an integer $m$.

The next $m$ lines each contain four space-separated integers $x_1, y_1, x_2, y_2$, representing the query rectangles.

Output

For each query, output a single line containing a decimal number between $0$ and $1$, representing the answer.

Examples

Input 1

2
1 1 4 4
2 1 4 3
4
1 1 6 6
1 1 3 3
2 1 3 3
1 2 2 4

Output 1

1
0.6
0.4
0

Subtasks

Idea: nzhtl1477 & ccz181078, Solution: ccz181078, Code: ccz181078, Data: ccz181078

For $100\%$ of the data, $1 \le n, m \le 10^5$, $1 \le x_1, y_1, x_2, y_2 \le 10^6$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.