QOJ.ac

QOJ

시간 제한: 2.0 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓

#15305. Doo Doo Doo

통계

Little Ika: Doo Doo Doo ~.

Hyacinthia wants to go to the center of the "Cloud End Ruins" Eye of Dawn to search for loot, but there are $n$ walls blocking her path. The $i$-th wall is a circle centered at the origin $(0, 0)$ with a radius of $r_i$. There are $k_i$ doors on the wall, and the coordinates of the $j$-th door are given by $\left(r_i \cdot \cos \left(\frac{2\pi}{M} \cdot p_{i,j}\right), r_i \cdot \sin \left(\frac{2\pi}{M} \cdot p_{i,j}\right)\right)$. The thickness of the wall and the width of the doors are negligible, and Hyacinthia cannot fly over the walls.

Hyacinthia wants to ask you $m$ times. Each time she will tell you her starting point, and you need to answer what the shortest distance to the center is. The starting point is guaranteed to be on the inner side of a wall and right next to the wall surface.

Input

The first line contains two integers $n, m$ ($2 \le n \le 2 \cdot 10^5, 1 \le m \le 2 \cdot 10^5$), representing the number of walls and the number of queries.

The next $n$ lines describe each wall. Each line starts with two integers $r_i, k_i$ ($1 \le r_i \le 10^8, 0 \le k_i \le 2 \cdot 10^5$), representing that the $i$-th wall is a circle with radius $r_i$ and has $k_i$ doors. Following this are $k_i$ integers $p_{i,1}, p_{i,2}, \dots, p_{i,k_i}$, representing that the coordinates of the $j$-th door are $\left(r_i \cdot \cos \left(\frac{2\pi}{M} \cdot p_{i,j}\right), r_i \cdot \sin \left(\frac{2\pi}{M} \cdot p_{i,j}\right)\right)$, where $M = 3.6 \cdot 10^8$. It is guaranteed that $0 \le p_{i,1} < p_{i,2} < \dots < p_{i,k_i} < M$, $k_n = 0$, $\sum_{i=1}^n k_i \le 2 \cdot 10^5$, and $1 \le r_1 < r_2 < \dots < r_n \le 10^8$.

The next $m$ lines each contain two integers $t_i, q_i$, indicating that if Hyacinthia starts from the inside of the $t_i$-th wall at the point $\left(r_{t_i} \cdot \cos \left(\frac{2\pi}{M} \cdot q_i\right), r_{t_i} \cdot \sin \left(\frac{2\pi}{M} \cdot q_i\right)\right)$, what is the shortest distance to the origin (if it is not reachable, please output "-1").

Output

For each query, output a single line with a floating-point number representing the answer. If it is not reachable, output "-1". An answer is considered correct if the relative or absolute error does not exceed $10^{-6}$ compared to the standard answer.

Examples

Input 1

3 4
2 2 0 90000000
5 0
8 0
1 114514
2 0
2 180000000
3 233

Output 1

2.0000000000
5.0000000000
7.4056093871
-1

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.