B. Wet Boxes

Codeforces
IDCF10079B
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Bob works in a warehouse which contains a large pile of boxes. The position of a box can be described with a pair of integers (x, y). Each box either stands on the ground (y = 0) or stands on top of two boxes with positions (x, y - 1) and (x + 1, y - 1) (see the figure). Sometimes the contents of a box leak out and the box gets wet. When a box becomes wet, so do the two boxes below it. Given a list of boxes that leak in succession, help Bob count how many dry boxes became wet after each leak. Don't include boxes that were already wet. The first line contains a single integer n, the number of leaking boxes (1 ≤ n ≤ 105). The i-th of the next n lines contains two space-separated integers xi and yi, the position of the i-th leaking box (0 ≤ xi, yi ≤ 109). Output n lines: in the i-th line output the number of boxes that became wet after the i-th box had leaked. ## Input The first line contains a single integer n, the number of leaking boxes (1 ≤ n ≤ 105). The i-th of the next n lines contains two space-separated integers xi and yi, the position of the i-th leaking box (0 ≤ xi, yi ≤ 109). ## Output Output n lines: in the i-th line output the number of boxes that became wet after the i-th box had leaked. [samples]
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the number of leaking boxes. Let $ L = \{(x_i, y_i) \mid i \in \{1, \dots, n\}\} $ be the sequence of leaking box positions, where $ x_i, y_i \in \mathbb{Z}_{\geq 0} $. For any box at position $ (x, y) $, define its *support set* as: $$ S(x, y) = \left\{ (x', y') \in \mathbb{Z}^2 \mid y' \leq y,\ x' \in [x - (y - y'), x + (y - y')] \text{ and } x' + y' \equiv x + y \pmod{2} \right\} $$ This represents all boxes that are directly or indirectly supported by $ (x, y) $, forming a downward triangular region. Let $ W \subseteq \mathbb{Z}^2 $ be the set of all wet boxes (initially empty). **Constraints** 1. $ 1 \leq n \leq 10^5 $ 2. $ 0 \leq x_i, y_i \leq 10^9 $ for all $ i \in \{1, \dots, n\} $ **Objective** For each $ i \in \{1, \dots, n\} $, compute: $$ c_i = \left| S(x_i, y_i) \setminus W \right| $$ then update: $$ W \leftarrow W \cup S(x_i, y_i) $$ Output $ c_i $ for each $ i $.
API Response (JSON)
{
  "problem": {
    "name": "B. Wet Boxes",
    "description": {
      "content": "Bob works in a warehouse which contains a large pile of boxes. The position of a box can be described with a pair of integers (x, y). Each box either stands on the ground (y = 0) or stands on top of t",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10079B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Bob works in a warehouse which contains a large pile of boxes. The position of a box can be described with a pair of integers (x, y). Each box either stands on the ground (y = 0) or stands on top of t...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of leaking boxes.  \nLet $ L = \\{(x_i, y_i) \\mid i \\in \\{1, \\dots, n\\}\\} $ be the sequence of leaking box positions, where $ x_i, y_i \\in \\mat...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments