{"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 - a2) + ... + θ(snx - an), where si =  ± 1. Calculate its values for argument values x1, x2, ..., xm.\n\nThe first line contains a single integer n (1 ≤ n ≤ 200000) — the number of the summands in the function.\n\nEach 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.\n\nThe 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.\n\nThe last line contains m integers x1, ..., xm ( - 109 ≤ xi ≤ 109) separated by spaces — the argument values themselves.\n\nOutput m lines. i-th line should contain the value of f(xi).\n\n## Input\n\nThe 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.\n\n## Output\n\nOutput m lines. i-th line should contain the value of f(xi).\n\n[samples]","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}^+$ be the number of summands.  \nFor $i \\in \\{1, \\dots, n\\}$, let $s_i \\in \\{-1, 1\\}$ and $a_i \\in \\mathbb{Z}$ define the $i$-th term.  \nDefine the function $f : \\mathbb{R} \\to \\mathbb{Z}$ as:  \n$$\nf(x) = \\sum_{i=1}^{n} \\theta(s_i x - a_i)\n$$\n\nLet $m \\in \\mathbb{Z}^+$ be the number of query points.  \nLet $X = (x_1, x_2, \\dots, x_m)$ be a sequence of real numbers where $x_j \\in \\mathbb{Z}$ for all $j$.\n\n**Constraints**  \n1. $1 \\leq n \\leq 200000$  \n2. $s_i \\in \\{-1, 1\\}$, $-10^9 \\leq a_i \\leq 10^9$ for all $i \\in \\{1, \\dots, n\\}$  \n3. $1 \\leq m \\leq 200000$  \n4. $-10^9 \\leq x_j \\leq 10^9$ for all $j \\in \\{1, \\dots, m\\}$\n\n**Objective**  \nFor each $j \\in \\{1, \\dots, m\\}$, compute:  \n$$\nf(x_j) = \\sum_{i=1}^{n} \\theta(s_i x_j - a_i)\n$$","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF10018M","tags":[],"sample_group":[],"created_at":"2026-03-03 11:00:39"}}