C. Rectangles

Codeforces
IDCF1028C
Time2000ms
Memory256MB
Difficulty
geometryimplementationsortings
English · Original
Chinese · Translation
Formal · Original
You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary. Find any point with integer coordinates that belongs to at least $(n-1)$ given rectangles. ## Input The first line contains a single integer $n$ ($2 \le n \le 132\,674$) — the number of given rectangles. Each the next $n$ lines contains four integers $x_1$, $y_1$, $x_2$ and $y_2$ ($-10^9 \le x_1 &lt; x_2 \le 10^9$, $-10^9 \le y_1 &lt; y_2 \le 10^9$) — the coordinates of the bottom left and upper right corners of a rectangle. ## Output Print two integers $x$ and $y$ — the coordinates of any point that belongs to at least $(n-1)$ given rectangles. [samples] ## Note The picture below shows the rectangles in the first and second samples. The possible answers are highlighted. <center>![image](https://espresso.codeforces.com/e47a869e382d2295eeb08173b4b637ceb9c1520d.png)</center>The picture below shows the rectangles in the third and fourth samples. <center>![image](https://espresso.codeforces.com/bff8ead23110ce820ca90a087d0cf0031aa73067.png)</center>
给定平面上的 $n$ 个矩形,每个矩形由其左下角和右上角的坐标给出。在给定的 $n$ 个矩形中,有 $(n -1)$ 个矩形存在一个公共点。一个点属于某个矩形,当且仅当该点严格位于矩形内部或位于其边界上。 请找出任意一个具有整数坐标的点,使得该点至少属于给定的 $(n -1)$ 个矩形。 第一行包含一个整数 $n$ ($2 lt.eq n lt.eq 132 thin 674$) —— 矩形的数量。 接下来的 $n$ 行,每行包含四个整数 $x_1$, $y_1$, $x_2$ 和 $y_2$ ($-10^9 lt.eq x_1 < x_2 lt.eq 10^9$, $-10^9 lt.eq y_1 < y_2 lt.eq 10^9$) —— 分别表示一个矩形的左下角和右上角的坐标。 请输出两个整数 $x$ 和 $y$ —— 任意一个至少属于 $(n -1)$ 个给定矩形的点的坐标。 下图展示了第一和第二个样例中的矩形,可能的答案已高亮显示。 下图展示了第三和第四个样例中的矩形。 ## Input 第一行包含一个整数 $n$ ($2 lt.eq n lt.eq 132 thin 674$) —— 矩形的数量。接下来的 $n$ 行,每行包含四个整数 $x_1$, $y_1$, $x_2$ 和 $y_2$ ($-10^9 lt.eq x_1 < x_2 lt.eq 10^9$, $-10^9 lt.eq y_1 < y_2 lt.eq 10^9$) —— 分别表示一个矩形的左下角和右上角的坐标。 ## Output 请输出两个整数 $x$ 和 $y$ —— 任意一个至少属于 $(n -1)$ 个给定矩形的点的坐标。 [samples] ## Note 下图展示了第一和第二个样例中的矩形,可能的答案已高亮显示。下图展示了第三和第四个样例中的矩形。
**Definitions** Let $ n \in \mathbb{Z} $ with $ 2 \leq n \leq 132674 $. Let $ R_i = [x_{i,1}, x_{i,2}] \times [y_{i,1}, y_{i,2}] \subseteq \mathbb{R}^2 $ for $ i \in \{1, \dots, n\} $ be the given axis-aligned rectangles, where $ x_{i,1} < x_{i,2} $, $ y_{i,1} < y_{i,2} $, and all coordinates are integers. **Given** There exists a point $ p \in \mathbb{R}^2 $ such that $ p $ lies in at least $ n-1 $ of the rectangles $ R_1, \dots, R_n $. **Objective** Find any point $ (x, y) \in \mathbb{Z}^2 $ such that $ (x, y) \in R_i $ for at least $ n-1 $ indices $ i \in \{1, \dots, n\} $. **Constraints** - $ -10^9 \leq x_{i,1} < x_{i,2} \leq 10^9 $ - $ -10^9 \leq y_{i,1} < y_{i,2} \leq 10^9 $ - All rectangle boundaries are inclusive (i.e., point belongs to rectangle if on boundary). - The input guarantees that at least one such integer point exists.
Samples
Input #1
3
0 0 1 1
1 1 2 2
3 0 4 1
Output #1
1 1
Input #2
3
0 0 1 1
0 1 1 2
1 0 2 1
Output #2
1 1
Input #3
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output #3
1 1
Input #4
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output #4
3 4
API Response (JSON)
{
  "problem": {
    "name": "C. Rectangles",
    "description": {
      "content": "You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF1028C"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given $n$ rectangles on a plane with coordinates of their bottom left and upper right points. Some $(n-1)$ of the given $n$ rectangles have some common point. A point belongs to a rectangle if...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "给定平面上的 $n$ 个矩形,每个矩形由其左下角和右上角的坐标给出。在给定的 $n$ 个矩形中,有 $(n -1)$ 个矩形存在一个公共点。一个点属于某个矩形,当且仅当该点严格位于矩形内部或位于其边界上。\n\n请找出任意一个具有整数坐标的点,使得该点至少属于给定的 $(n -1)$ 个矩形。\n\n第一行包含一个整数 $n$ ($2 lt.eq n lt.eq 132 thin 674$) —— 矩形的...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ with $ 2 \\leq n \\leq 132674 $.  \nLet $ R_i = [x_{i,1}, x_{i,2}] \\times [y_{i,1}, y_{i,2}] \\subseteq \\mathbb{R}^2 $ for $ i \\in \\{1, \\dots, n\\} $ be the given...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments