F. Finally, christmas!

Codeforces
IDCF10244F
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
The christmas spirit is taking over the city of Arcoverde! In honor of this special day, the mayor of this renowned metropolis decided to decorate all of the city's front view. To do this, he asked his engineer friends Icaro and Cortizo how much it would cost. It is known that the mayor likes to save as much money as possible. Therefore, Icaro and Cortizo need to find out what is the minimum area necessary to comprise the entire city's front view. Arcoverde is made only of rectangular buildings, in two dimensions, and all buildings were built on the same base height, as shown on the picture below. Icaro and Cortizo were very tired, since they were also responsible for building the biggest christmas tree ever seen on Pernambuco, so they asked for your help. The first input line contains an integer $N$($1 <= N <= 10^5$), indicating the number of buildings in Arcoverde. Then, $N$ lines follow, each one containing three integers $L_i$ ($0 <= L_i < 10^9$), $R_i$ ($L_i < R_i <= 10^9$) and $H_i$ ($1 <= H_i <= 10^6$), which are, respectively, the left X-coordinate, the right X-coordinate and the height of the $i$-th building. The output consists in a single integer number, which is the minimum area required to decorate the entire front view of Arcoverde. ## Input The first input line contains an integer $N$($1 <= N <= 10^5$), indicating the number of buildings in Arcoverde. Then, $N$ lines follow, each one containing three integers $L_i$ ($0 <= L_i < 10^9$), $R_i$ ($L_i < R_i <= 10^9$) and $H_i$ ($1 <= H_i <= 10^6$), which are, respectively, the left X-coordinate, the right X-coordinate and the height of the $i$-th building. ## Output The output consists in a single integer number, which is the minimum area required to decorate the entire front view of Arcoverde. [samples]
**Definitions** Let $ N \in \mathbb{Z}^+ $ be the number of buildings. For each building $ i \in \{1, \dots, N\} $, define: - $ L_i \in \mathbb{Z} $: left x-coordinate, - $ R_i \in \mathbb{Z} $: right x-coordinate, with $ L_i < R_i $, - $ H_i \in \mathbb{Z}^+ $: height. Each building is represented as a rectangle $ [L_i, R_i] \times [0, H_i] $. **Constraints** 1. $ 1 \leq N \leq 10^5 $ 2. $ 0 \leq L_i < R_i \leq 10^9 $ 3. $ 1 \leq H_i \leq 10^6 $ **Objective** Compute the area of the union of all rectangles: $$ \text{Area} = \int_{x=-\infty}^{\infty} \max_{i: L_i \leq x < R_i} H_i \, dx $$ Equivalently, compute the area of the skyline formed by overlapping rectangles aligned on the x-axis, where at each x-coordinate, the height is the maximum height of any building covering that x.
API Response (JSON)
{
  "problem": {
    "name": "F. Finally, christmas!",
    "description": {
      "content": "The christmas spirit is taking over the city of Arcoverde! In honor of this special day, the mayor of this renowned metropolis decided to decorate all of the city's front view. To do this, he asked hi",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10244F"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "The christmas spirit is taking over the city of Arcoverde! In honor of this special day, the mayor of this renowned metropolis decided to decorate all of the city's front view. To do this, he asked hi...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ N \\in \\mathbb{Z}^+ $ be the number of buildings.  \nFor each building $ i \\in \\{1, \\dots, N\\} $, define:  \n- $ L_i \\in \\mathbb{Z} $: left x-coordinate,  \n- $ R_i \\in \\mathbb{Z} ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments