E. Satellites

Codeforces
IDCF856E
Time2000ms
Memory256MB
Difficulty
English · Original
Chinese · Translation
Formal · Original
Real Cosmic Communications is the largest telecommunication company on a far far away planet, located at the very edge of the universe. RCC launches communication satellites. The planet is at the very edge of the universe, so its form is half of a circle. Its radius is _r_, the ends of its diameter are points _A_ and _B_. The line _AB_ is the edge of the universe, so one of the half-planes contains nothing, neither the planet, nor RCC satellites, nor anything else. Let us introduce coordinates in the following way: the origin is at the center of _AB_ segment, _OX_ axis coincides with line _AB_, the planet is completely in _y_ > 0 half-plane. The satellite can be in any point of the universe, except the planet points. Satellites are never located beyond the edge of the universe, nor on the edge itself — that is, they have coordinate _y_ > 0. Satellite antennas are directed in such way that they cover the angle with the vertex in the satellite, and edges directed to points _A_ and _B_. Let us call this area the satellite coverage area. The picture below shows coordinate system and coverage area of a satellite. <center>![image](https://espresso.codeforces.com/048abf621d8cfe061e9044bc7fa421f8f1a16a34.png)</center>When RCC was founded there were no satellites around the planet. Since then there have been several events of one of the following types: 1. _1 x y_ — launch the new satellite and put it to the point (_x_, _y_). Satellites never move and stay at the point they were launched. Let us assign the number _i_ to the _i_\-th satellite in order of launching, starting from one. 2. _2 i_ — remove satellite number _i_. 3. _3 i j_ — make an attempt to create a communication channel between satellites _i_ and _j_. To create a communication channel a repeater is required. It must not be located inside the planet, but can be located at its half-circle border, or above it. Repeater must be in coverage area of both satellites _i_ and _j_. To avoid signal interference, it must not be located in coverage area of any other satellite. Of course, the repeater must be within the universe, it must have a coordinate _y_ > 0. For each attempt to create a communication channel you must find out whether it is possible. Sample test has the following satellites locations: <center>![image](https://espresso.codeforces.com/faf45925bd82aff34be526e1fedeedbc2625b1a0.png)</center> ## Input The first line of input data contains integers _r_ and _n_ — radius of the planet and the number of events (1 ≤ _r_ ≤ 109, 1 ≤ _n_ ≤ 5·105). Each of the following _n_ lines describe events in the specified format. Satellite coordinates are integer, the satisfy the following constraints |_x_| ≤ 109, 0 < _y_ ≤ 109. No two satellites that simultaneously exist can occupy the same point. Distance from each satellite to the center of the planet is strictly greater than _r_. It is guaranteed that events of types 2 and 3 only refer to satellites that exist at the moment. For all events of type 3 the inequality _i_ ≠ _j_ is satisfied. ## Output For each event of type 3 print «_YES_» on a separate line, if it is possible to create a communication channel, or «_NO_» if it is impossible. [samples]
Real Cosmic Communications 是位于宇宙最边缘的一颗遥远星球上最大的电信公司。RCC 发射通信卫星。 这颗星球位于宇宙的边缘,因此其形状是半个圆。其半径为 $r$,直径的两端为点 $A$ 和 $B$。直线 $AB$ 是宇宙的边界,因此其中一个半平面不包含任何东西——既没有星球,也没有 RCC 卫星,更没有其他任何事物。我们按如下方式建立坐标系:原点位于线段 $AB$ 的中心,$OX$ 轴与直线 $AB$ 重合,星球完全位于 $y > 0$ 的半平面内。 卫星可以位于宇宙中的任意一点,但不能位于星球上。卫星永远不会位于宇宙边界之外或边界上——即它们的坐标满足 $y > 0$。卫星天线的朝向使得它们覆盖一个以卫星为顶点、两边分别指向点 $A$ 和 $B$ 的角。我们将这一区域称为卫星的 $\text{coverage area}$(覆盖区域)。 下图展示了坐标系和一个卫星的覆盖区域。 当 RCC 成立时,星球周围没有卫星。从那时起,发生了以下几种类型的事件: 对于每次尝试建立通信信道,你必须判断是否可能实现。 样例测试用例中的卫星位置如下: 输入数据的第一行包含整数 $r$ 和 $n$ —— 星球的半径和事件数量($1 ≤ r ≤ 10^9$,$1 ≤ n ≤ 5·10^5$)。 接下来的 $n$ 行每行描述一个事件,格式如上所述。 卫星的坐标为整数,满足以下约束:$|x| ≤ 10^9$,$0 < y ≤ 10^9$。同时存在的任意两个卫星不会占据同一个点。每个卫星到星球中心的距离严格大于 $r$。 保证类型为 $2$ 和 $3$ 的事件仅涉及当前存在的卫星。对于所有类型为 $3$ 的事件,满足 $i ≠ j$。 对于每个类型为 $3$ 的事件,如果可以建立通信信道,则在单独一行输出 «_YES_»;否则输出 «_NO_»。 ## Input 输入数据的第一行包含整数 $r$ 和 $n$ —— 星球的半径和事件数量($1 ≤ r ≤ 10^9$,$1 ≤ n ≤ 5·10^5$)。接下来的 $n$ 行每行描述一个事件,格式如上所述。卫星的坐标为整数,满足以下约束:$|x| ≤ 10^9$,$0 < y ≤ 10^9$。同时存在的任意两个卫星不会占据同一个点。每个卫星到星球中心的距离严格大于 $r$。保证类型为 $2$ 和 $3$ 的事件仅涉及当前存在的卫星。对于所有类型为 $3$ 的事件,满足 $i ≠ j$。 ## Output 对于每个类型为 $3$ 的事件,如果可以建立通信信道,则在单独一行输出 «_YES_»;否则输出 «_NO_»。 [samples]
**Definitions:** - Let the planet be the upper semicircle of radius $ r $, centered at the origin $ O = (0, 0) $, with diameter endpoints $ A = (-r, 0) $, $ B = (r, 0) $. The planet occupies the set $ \{(x, y) \mid x^2 + y^2 \leq r^2, y \geq 0\} $. - Satellites are points $ S = (x, y) \in \mathbb{R}^2 $ such that $ y > 0 $ and $ x^2 + y^2 > r^2 $. - The **coverage area** of a satellite at $ S = (x, y) $ is the set of points in the plane visible from $ S $ within the angle $ \angle ASB $, i.e., the conical region bounded by rays $ \overrightarrow{SA} $ and $ \overrightarrow{SB} $. **Given:** - Initial set of satellites: empty. - $ n $ events of three types: 1. **Type 1**: Add a satellite at point $ (x, y) $, with integer coordinates satisfying $ y > 0 $, $ x^2 + y^2 > r^2 $. 2. **Type 2**: Remove the satellite added at the $ i $-th event (among all previous events of type 1). 3. **Type 3**: Given two existing satellites $ i $ and $ j $, determine whether their coverage areas **intersect**. **Objective:** For each type-3 event, output "YES" if the coverage areas of the two satellites intersect; "NO" otherwise. --- **Mathematical Formulation:** Let $ S_i = (x_i, y_i) $, $ S_j = (x_j, y_j) $ be two satellite positions. Define the **coverage cone** of a satellite $ S = (x, y) $ as the set of points in the plane lying within the angle $ \angle ASB $, i.e., the convex cone with apex at $ S $, bounded by the two rays $ \overrightarrow{SA} $ and $ \overrightarrow{SB} $. The coverage area of $ S $ is the **infinite wedge**: $$ C(S) = \left\{ P \in \mathbb{R}^2 \mid P \text{ lies in the interior of } \angle ASB \right\} $$ This wedge can be characterized by the two vectors: - $ \vec{u} = \overrightarrow{SA} = (-r - x, -y) $ - $ \vec{v} = \overrightarrow{SB} = (r - x, -y) $ The coverage area $ C(S) $ is the set of points $ P $ such that the vector $ \overrightarrow{SP} $ lies in the convex cone spanned by $ \vec{u} $ and $ \vec{v} $, i.e., $ \overrightarrow{SP} = \alpha \vec{u} + \beta \vec{v} $ for some $ \alpha, \beta \geq 0 $, not both zero. Two coverage areas $ C(S_i) $ and $ C(S_j) $ **intersect** if and only if there exists a point $ P \in \mathbb{R}^2 $ such that $ P \in C(S_i) \cap C(S_j) $. --- **Key Geometric Insight:** The coverage area of a satellite $ S = (x, y) $ is the set of points visible from $ S $ between $ A $ and $ B $. Since both $ A $ and $ B $ lie on the x-axis, and the satellite is above the x-axis, the coverage area is the region **between the two lines** $ SA $ and $ SB $, extending infinitely upward. Thus, the coverage area is the **infinite angular sector** between the two lines $ SA $ and $ SB $, and **does not extend below the satellite**. Two such sectors intersect **if and only if** the two angular sectors (defined by their bounding rays) overlap in the plane. This occurs if and only if the two wedges have overlapping angular spans when projected onto the unit circle centered at their respective apices — but since the wedges are defined by fixed endpoints $ A $ and $ B $, a better approach is: > **Two satellites $ S_i $ and $ S_j $ have intersecting coverage areas if and only if the line segment $ S_iS_j $ intersects the segment $ AB $, or one satellite lies within the coverage cone of the other.** But a more precise and computationally tractable condition is: --- **Final Formal Condition (for Type 3 events):** Let $ S_i = (x_i, y_i) $, $ S_j = (x_j, y_j) $. Define the **angular span** of satellite $ S $ as the angle $ \angle ASB $, and the **directions** from $ S $ to $ A $ and $ B $. The coverage areas of $ S_i $ and $ S_j $ intersect **if and only if** the two cones $ C(S_i) $ and $ C(S_j) $ have non-empty intersection. This happens **if and only if** the **convex hull** of the four points $ A, B, S_i, S_j $ does **not** separate the two satellites in angular order around the circle. A more efficient characterization: > The coverage areas of $ S_i $ and $ S_j $ intersect **if and only if** the line segment $ S_iS_j $ intersects the segment $ AB $, **or** $ S_j $ lies inside the cone $ C(S_i) $, **or** $ S_i $ lies inside the cone $ C(S_j) $. But even better: since both cones are defined by rays to the fixed points $ A $ and $ B $, the intersection of two such cones is non-empty **if and only if** the two cones overlap in the angular space around the upper half-plane. This reduces to checking whether the **two intervals** of angles (from $ S_i $ and $ S_j $) between $ \overrightarrow{SA} $ and $ \overrightarrow{SB} $ **overlap**. But since the cones are defined by fixed endpoints $ A $ and $ B $, we can use the following **necessary and sufficient condition**: --- **Key Theorem (Geometric):** The coverage areas of two satellites $ S_i $ and $ S_j $ intersect **if and only if** the **line segment $ S_iS_j $** intersects the **line segment $ AB $**. **Why?** - The coverage area of a satellite is the set of points visible from $ S $ within $ \angle ASB $, i.e., the region bounded by rays $ SA $ and $ SB $. - The union of all such coverage areas for all satellites covers the region **above** the planet and **between** the two lines $ SA $ and $ SB $. - Two such regions intersect if and only if their defining wedges overlap — which occurs precisely when the line segment connecting the two satellites crosses the diameter $ AB $, because $ AB $ is the "base" of both wedges. **Proof Sketch:** - If $ S_iS_j $ crosses $ AB $, then the two wedges must overlap in the region around the crossing point. - If $ S_iS_j $ does not cross $ AB $, then both satellites lie entirely on one side of the line $ AB $, and since both wedges are bounded by rays to $ A $ and $ B $, their angular spans are disjoint in the upper half-plane. **Therefore:** > For a type-3 event with satellites $ i $ and $ j $, the answer is **YES** if and only if the line segment $ S_iS_j $ intersects the segment $ AB $, where $ A = (-r, 0) $, $ B = (r, 0) $. --- **Final Mathematical Statement:** Let $ S_i = (x_i, y_i) $, $ S_j = (x_j, y_j) $ be two satellite positions. Let $ A = (-r, 0) $, $ B = (r, 0) $. Define segment $ AB = \{ (x, 0) \mid -r \leq x \leq r \} $. Define segment $ S_iS_j = \{ (1-t)S_i + tS_j \mid t \in [0,1] \} $. Then: $$ \boxed{ \text{Answer} = \begin{cases} \text{YES} & \text{if } S_iS_j \cap AB \neq \emptyset \\ \text{NO} & \text{otherwise} \end{cases} } $$ **Implementation Note:** To check if segment $ S_iS_j $ intersects segment $ AB $: - Since $ AB $ lies on the x-axis from $ (-r, 0) $ to $ (r, 0) $, and both $ S_i, S_j $ have $ y > 0 $, the segments intersect if and only if the line $ S_iS_j $ crosses the x-axis **within** $ [-r, r] $. That is: - Let $ t \in [0,1] $ be the parameter where $ y(t) = (1-t)y_i + t y_j = 0 $. - Solve: $ t = \frac{y_i}{y_i - y_j} $ (if $ y_i \ne y_j $). - If $ t \in [0,1] $, then the intersection point is $ x = (1-t)x_i + t x_j $. - Check if $ -r \leq x \leq r $. Alternatively, use the **crossing condition**: The segment $ S_iS_j $ intersects $ AB $ if and only if: $$ (y_i > 0 \land y_j > 0) \quad \text{and} \quad \text{the x-intercept of line } S_iS_j \text{ lies in } [-r, r] $$ The x-intercept $ x_0 $ of line through $ S_i, S_j $ is: $$ x_0 = x_i - y_i \cdot \frac{x_j - x_i}{y_j - y_i} $$ Then: $$ \boxed{ \text{YES} \iff -r \leq x_0 \leq r } $$ (Note: Since $ y_i, y_j > 0 $, the line crosses the x-axis exactly once if $ y_i \ne y_j $. If $ y_i = y_j $, the line is horizontal and never crosses x-axis → no intersection → NO.) --- **Summary:** For each type-3 event with satellites $ i, j $: - If $ y_i = y_j $: output "NO" (line parallel to AB, no intersection). - Else: $$ x_0 = x_i - y_i \cdot \frac{x_j - x_i}{y_j - y_i} $$ $$ \text{Output "YES" if } -r \leq x_0 \leq r, \text{ else "NO"} $$
Samples
Input #1
5 8
1 -5 8
1 -4 8
1 -3 8
1 2 7
3 1 3
2 2
3 1 3
3 3 4
Output #1
NO
YES
YES
API Response (JSON)
{
  "problem": {
    "name": "E. Satellites",
    "description": {
      "content": "Real Cosmic Communications is the largest telecommunication company on a far far away planet, located at the very edge of the universe. RCC launches communication satellites. The planet is at the ver",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF856E"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Real Cosmic Communications is the largest telecommunication company on a far far away planet, located at the very edge of the universe. RCC launches communication satellites.\n\nThe planet is at the ver...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Real Cosmic Communications 是位于宇宙最边缘的一颗遥远星球上最大的电信公司。RCC 发射通信卫星。\n\n这颗星球位于宇宙的边缘,因此其形状是半个圆。其半径为 $r$,直径的两端为点 $A$ 和 $B$。直线 $AB$ 是宇宙的边界,因此其中一个半平面不包含任何东西——既没有星球,也没有 RCC 卫星,更没有其他任何事物。我们按如下方式建立坐标系:原点位于线段 $AB$ 的中...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions:**\n\n- Let the planet be the upper semicircle of radius $ r $, centered at the origin $ O = (0, 0) $, with diameter endpoints $ A = (-r, 0) $, $ B = (r, 0) $. The planet occupies the set ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments