M. Heaviside Function

Codeforces
IDCF10018M
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Heaviside function is defined as the piecewise constant function whose value is zero for negative argument and one for non-negative argument: You are given the function f(x) = θ(s1x - a1) + θ(s2x - a2) + ... + θ(snx - an), where si =  ± 1. Calculate its values for argument values x1, x2, ..., xm. The first line contains a single integer n (1 ≤ n ≤ 200000) — the number of the summands in the function. Each of the next n lines contains two integers separated by space — si and ai (si =  ± 1,  - 109 ≤ ai ≤ 109) — parameters of the i-th summand. The next line contains a single integer m (1 ≤ m ≤ 200000) — the number of the argument values you should calculate the value of the function for. The last line contains m integers x1, ..., xm ( - 109 ≤ xi ≤ 109) separated by spaces — the argument values themselves. Output m lines. i-th line should contain the value of f(xi). ## Input The first line contains a single integer n (1 ≤ n ≤ 200000) — the number of the summands in the function.Each of the next n lines contains two integers separated by space — si and ai (si =  ± 1,  - 109 ≤ ai ≤ 109) — parameters of the i-th summand.The next line contains a single integer m (1 ≤ m ≤ 200000) — the number of the argument values you should calculate the value of the function for.The last line contains m integers x1, ..., xm ( - 109 ≤ xi ≤ 109) separated by spaces — the argument values themselves. ## Output Output m lines. i-th line should contain the value of f(xi). [samples]
**Definitions** Let $\theta : \mathbb{R} \to \{0,1\}$ be the Heaviside function: $$ \theta(x) = \begin{cases} 0 & \text{if } x < 0 \\ 1 & \text{if } x \geq 0 \end{cases} $$ Let $n \in \mathbb{Z}^+$ be the number of summands. For $i \in \{1, \dots, n\}$, let $s_i \in \{-1, 1\}$ and $a_i \in \mathbb{Z}$ define the $i$-th term. Define the function $f : \mathbb{R} \to \mathbb{Z}$ as: $$ f(x) = \sum_{i=1}^{n} \theta(s_i x - a_i) $$ Let $m \in \mathbb{Z}^+$ be the number of query points. Let $X = (x_1, x_2, \dots, x_m)$ be a sequence of real numbers where $x_j \in \mathbb{Z}$ for all $j$. **Constraints** 1. $1 \leq n \leq 200000$ 2. $s_i \in \{-1, 1\}$, $-10^9 \leq a_i \leq 10^9$ for all $i \in \{1, \dots, n\}$ 3. $1 \leq m \leq 200000$ 4. $-10^9 \leq x_j \leq 10^9$ for all $j \in \{1, \dots, m\}$ **Objective** For each $j \in \{1, \dots, m\}$, compute: $$ f(x_j) = \sum_{i=1}^{n} \theta(s_i x_j - a_i) $$
API Response (JSON)
{
  "problem": {
    "name": "M. Heaviside Function",
    "description": {
      "content": "Heaviside function is defined as the piecewise constant function whose value is zero for negative argument and one for non-negative argument: You are given the function f(x) = θ(s1x - a1) + θ(s2x - a",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10018M"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Heaviside function is defined as the piecewise constant function whose value is zero for negative argument and one for non-negative argument:\n\nYou are given the function f(x) = θ(s1x - a1) + θ(s2x - a...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $\\theta : \\mathbb{R} \\to \\{0,1\\}$ be the Heaviside function:  \n$$\n\\theta(x) = \n\\begin{cases}\n0 & \\text{if } x < 0 \\\\\n1 & \\text{if } x \\geq 0\n\\end{cases}\n$$\n\nLet $n \\in \\mathbb{Z}...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments