CF1140F.Extending Set of Points
省选/NOI-
通过率:0%
时间限制:3.50s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For a given set of two-dimensional points S, let's denote its extension E(S) as the result of the following algorithm:
Create another set of two-dimensional points R, which is initially equal to S. Then, while there exist four numbers x1, y1, x2 and y2 such that (x1,y1)∈R, (x1,y2)∈R, (x2,y1)∈R and (x2,y2)∈/R, add (x2,y2) to R. When it is impossible to find such four integers, let R be the result of the algorithm.
Now for the problem itself. You are given a set of two-dimensional points S, which is initially empty. You have to process two types of queries: add some point to S, or remove some point from it. After each query you have to compute the size of E(S).
对于给定的二维点集 S,定义其扩展集 E(S) 为以下算法的结果:
另创建一个二维点集 R,初始时 R=S。然后,只要存在四个数 x1、y1、x2 和 y2,使得 (x1,y1)∈R、(x1,y2)∈R、(x2,y1)∈R,但 (x2,y2)∈/R,就将点 (x2,y2) 加入 R。当无法再找到满足上述条件的四个数时,令此时的 R 为该算法的结果。
现在给出本题的具体要求:你被给定一个初始为空的二维点集 S,需处理两类查询:向 S 中添加某个点,或从 S 中删除某个点。每次查询后,你都需要计算 E(S) 的大小。
输入格式
The first line contains one integer q (1≤q≤3⋅105) — the number of queries.
Then q lines follow, each containing two integers xi, yi (1≤xi,yi≤3⋅105), denoting i-th query as follows: if (xi,yi)∈S, erase it from S, otherwise insert (xi,yi) into S.
第一行包含一个整数 q(1≤q≤3⋅105),表示查询次数。
接下来有 q 行,每行包含两个整数 xi、yi(1≤xi,yi≤3⋅105),表示第 i 次查询:若 (xi,yi)∈S,则将其从 S 中删除;否则将 (xi,yi) 插入 S。
输出格式
Print q integers. i-th integer should be equal to the size of E(S) after processing first i queries.
输出 q 个整数。其中第 i 个整数应等于处理前 i 个查询后集合 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测评打分。不知道怎么写?