CF1140F.Extending Set of Points

省选/NOI-

通过率:0%

时间限制:3.50s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

For a given set of two-dimensional points SS, let's denote its extension E(S)E(S) as the result of the following algorithm:

Create another set of two-dimensional points RR, which is initially equal to SS. Then, while there exist four numbers x1x_1, y1y_1, x2x_2 and y2y_2 such that (x1,y1)∈R(x_1, y_1) \in R, (x1,y2)∈R(x_1, y_2) \in R, (x2,y1)∈R(x_2, y_1) \in R and (x2,y2)∉R(x_2, y_2) \notin R, add (x2,y2)(x_2, y_2) to RR. When it is impossible to find such four integers, let RR be the result of the algorithm.

Now for the problem itself. You are given a set of two-dimensional points SS, which is initially empty. You have to process two types of queries: add some point to SS, or remove some point from it. After each query you have to compute the size of E(S)E(S).

对于给定的二维点集 SS,定义其扩展集 E(S)E(S) 为以下算法的结果:

另创建一个二维点集 RR,初始时 R=SR = S。然后,只要存在四个数 x1x_1、y1y_1、x2x_2 和 y2y_2,使得 (x1,y1)∈R(x_1, y_1) \in R、(x1,y2)∈R(x_1, y_2) \in R、(x2,y1)∈R(x_2, y_1) \in R,但 (x2,y2)∉R(x_2, y_2) \notin R,就将点 (x2,y2)(x_2, y_2) 加入 RR。当无法再找到满足上述条件的四个数时,令此时的 RR 为该算法的结果。

现在给出本题的具体要求:你被给定一个初始为空的二维点集 SS,需处理两类查询:向 SS 中添加某个点,或从 SS 中删除某个点。每次查询后,你都需要计算 E(S)E(S) 的大小。

输入格式

The first line contains one integer qq (1≤q≤3⋅1051 \le q \le 3 \cdot 10^5) — the number of queries.

Then qq lines follow, each containing two integers xix_i, yiy_i (1≤xi,yi≤3⋅1051 \le x_i, y_i \le 3 \cdot 10^5), denoting ii-th query as follows: if (xi,yi)∈S(x_i, y_i) \in S, erase it from SS, otherwise insert (xi,yi)(x_i, y_i) into SS.

第一行包含一个整数 qq(1≤q≤3⋅1051 \le q \le 3 \cdot 10^5),表示查询次数。

接下来有 qq 行,每行包含两个整数 xix_i、yiy_i(1≤xi,yi≤3⋅1051 \le x_i, y_i \le 3 \cdot 10^5),表示第 ii 次查询:若 (xi,yi)∈S(x_i, y_i) \in S,则将其从 SS 中删除;否则将 (xi,yi)(x_i, y_i) 插入 SS。

输出格式

Print qq integers. ii-th integer should be equal to the size of E(S)E(S) after processing first ii queries.

输出 qq 个整数。其中第 ii 个整数应等于处理前 ii 个查询后集合 E(S)E(S) 的大小。

输入输出样例

  • 输入#1

    7
    1 1
    1 2
    2 1
    2 2
    1 2
    1 3
    2 1

    输出#1

    1 2 4 4 4 6 3

输入解题思路,AI测评打分。不知道怎么写?

首页