F. Make Symmetrical

Codeforces
IDCF1028F
Time6000ms
Memory512MB
Difficulty
brute force
English · Original
Chinese · Translation
Formal · Original
Consider a set of points $A$, initially it is empty. There are three types of queries: 1. Insert a point $(x_i, y_i)$ to $A$. It is guaranteed that this point does not belong to $A$ at this moment. 2. Remove a point $(x_i, y_i)$ from $A$. It is guaranteed that this point belongs to $A$ at this moment. 3. Given a point $(x_i, y_i)$, calculate the minimum number of points required to add to $A$ to make $A$ symmetrical with respect to the line containing points $(0, 0)$ and $(x_i, y_i)$. Note that these points are not actually added to $A$, i.e. these queries are independent from each other. ## Input The first line contains a single integer $q$ ($1 \le q \le 2 \cdot 10^5$) — the number of queries. Each of the following $q$ lines describes a query and contains three integers $t_i$, $x_i$ and $y_i$ ( $ t_i \in {1, 2, 3}$, $1 \le x_i, y_i \le 112\,904$) — the type of the query and the coordinates of the point. Type $1$ is addition of the point, type $2$ is removal of the point, type $3$ is the query to compute the minimum number of points required to make $A$ symmetrical. It is guaranteed that there are no more than $10^5$ queries of type $3$ and no more than $10^5$ queries having type $1$ or $2$. ## Output For each query of the third type output a line with a single integer — the answer to this query. [samples] ## Note The first example is shown on the picture below. <center>![image](https://espresso.codeforces.com/e92a4dbc370c408fe8fad3167bfadd55fd250c82.png)</center>
[{"iden":"statement","content":"考虑一个点集 $A$,初始时为空。共有三种类型的查询:\n\n第一行包含一个整数 $q$($1 lt.eq q lt.eq 2 dot.op 10^5$)——查询的数量。\n\n接下来的 $q$ 行每行描述一个查询,包含三个整数 $t_i$、$x_i$ 和 $y_i$($t_i in {1, 2, 3}$,$1 lt.eq x_i, y_i lt.eq 112 thin 904$)——查询的类型和点的坐标。类型 $1$ 表示添加点,类型 $2$ 表示删除点,类型 $3$ 表示查询使 $A$ 对称所需的最少点数。\n\n保证类型 $3$ 的查询不超过 $10^5$ 次,类型 $1$ 或 $2$ 的查询合计不超过 $10^5$ 次。\n\n对于每个类型 $3$ 的查询,输出一行一个整数——该查询的答案。\n\n第一个示例如下图所示。\n\n"},{"iden":"input","content":"第一行包含一个整数 $q$($1 lt.eq q lt.eq 2 dot.op 10^5$)——查询的数量。接下来的 $q$ 行每行描述一个查询,包含三个整数 $t_i$、$x_i$ 和 $y_i$($t_i in {1, 2, 3}$,$1 lt.eq x_i, y_i lt.eq 112 thin 904$)——查询的类型和点的坐标。类型 $1$ 表示添加点,类型 $2$ 表示删除点,类型 $3$ 表示查询使 $A$ 对称所需的最少点数。保证类型 $3$ 的查询不超过 $10^5$ 次,类型 $1$ 或 $2$ 的查询合计不超过 $10^5$ 次。"},{"iden":"output","content":"对于每个类型 $3$ 的查询,输出一行一个整数——该查询的答案。"},{"iden":"examples","content":"输入121 1 61 6 11 5 51 2 33 4 41 3 23 7 72 2 32 6 13 8 82 5 53 1 1输出1022输入61 1 23 1 11 1 13 2 22 1 13 2 4输出110"},{"iden":"note","content":"第一个示例如下图所示。 "}] 请注意:根据要求,所有数学公式(如 $...$)、Typst 命令(如 lt.eq、dot.op、thin)均未改动,仅翻译了自然语言部分,且保持了原始换行与结构。输出为严格格式化的 JSON 数组。
**Definitions** Let $ A \subseteq \mathbb{Z}^2 $ be a multiset of points in the plane, initially empty. Let $ q \in \mathbb{Z} $ be the number of queries, with $ 1 \le q \le 2 \cdot 10^5 $. Each query is a triple $ (t_i, x_i, y_i) $, where $ t_i \in \{1, 2, 3\} $, and $ 1 \le x_i, y_i \le 112904 $. **Constraints** 1. $ 1 \le q \le 2 \cdot 10^5 $ 2. Number of type-3 queries $ \le 10^5 $ 3. Number of type-1 and type-2 queries combined $ \le 10^5 $ 4. For type-1: add point $ (x_i, y_i) $ to $ A $ (if already present, increment multiplicity). 5. For type-2: remove one occurrence of point $ (x_i, y_i) $ from $ A $ (if multiplicity > 0). 6. For type-3: compute the minimum number of points to add to $ A $ such that the resulting multiset is symmetric with respect to the origin (i.e., for every point $ (x, y) \in A $, the point $ (-x, -y) \in A $ with at least the same multiplicity). **Objective** For each query of type 3, output the minimum number of points to add to $ A $ to make it origin-symmetric. Let $ A $ be the current multiset of points. Define the *deficiency* of a point $ (x, y) \in A $ as: $$ d(x, y) = \max\left(0, \text{mult}_A(x, y) - \text{mult}_A(-x, -y)\right) $$ Then the minimum number of points to add is: $$ \sum_{(x, y) \in A} d(x, y) $$ Equivalently, since each asymmetric pair $ \{(x, y), (-x, -y)\} $ contributes $ |\text{mult}_A(x, y) - \text{mult}_A(-x, -y)| $, and each such difference is counted once (e.g., over a canonical representative), the total is: $$ \frac{1}{2} \sum_{(x, y) \in \mathbb{Z}^2} \left| \text{mult}_A(x, y) - \text{mult}_A(-x, -y) \right| $$ But since the multiset is finite and symmetric sum over all points is redundant, the efficient formulation is: $$ \sum_{\substack{(x, y) \in A \\ (x, y) \text{ lexicographically } \le (-x, -y)}} \max\left(0, \text{mult}_A(x, y) - \text{mult}_A(-x, -y)\right) $$ However, for computational clarity and correctness, the minimal number of points to add is simply: $$ \sum_{(x, y) \in A} \max\left(0, \text{mult}_A(x, y) - \text{mult}_A(-x, -y)\right) $$ This counts, for each point, how many more copies are needed of its symmetric counterpart to balance it.
Samples
Input #1
12
1 1 6
1 6 1
1 5 5
1 2 3
3 4 4
1 3 2
3 7 7
2 2 3
2 6 1
3 8 8
2 5 5
3 1 1
Output #1
1
0
2
2
Input #2
6
1 1 2
3 1 1
1 1 1
3 2 2
2 1 1
3 2 4
Output #2
1
1
0
API Response (JSON)
{
  "problem": {
    "name": "F. Make Symmetrical",
    "description": {
      "content": "Consider a set of points $A$, initially it is empty. There are three types of queries: 1.  Insert a point $(x_i, y_i)$ to $A$. It is guaranteed that this point does not belong to $A$ at this moment. ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 6000,
      "memory_limit": 524288
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF1028F"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Consider a set of points $A$, initially it is empty. There are three types of queries:\n\n1.  Insert a point $(x_i, y_i)$ to $A$. It is guaranteed that this point does not belong to $A$ at this moment.\n...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "[{\"iden\":\"statement\",\"content\":\"考虑一个点集 $A$,初始时为空。共有三种类型的查询:\\n\\n第一行包含一个整数 $q$($1 lt.eq q lt.eq 2 dot.op 10^5$)——查询的数量。\\n\\n接下来的 $q$ 行每行描述一个查询,包含三个整数 $t_i$、$x_i$ 和 $y_i$($t_i in {1, 2, 3}$,$1 lt.eq x_i, ...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ A \\subseteq \\mathbb{Z}^2 $ be a multiset of points in the plane, initially empty.  \nLet $ q \\in \\mathbb{Z} $ be the number of queries, with $ 1 \\le q \\le 2 \\cdot 10^5 $.  \nEach...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments