题意:对于点集S,定义函数F(S)为对S不断扩展到不能扩展时S的点数。一次扩展定义为如果有一个平行于坐标轴的矩形的三个点在S中,则第四个点加入S。

动态在S中加点删点,每次操作完后求F(S)的值。

解:首先有个结论就是,把这些点用平行于坐标轴的线段连接起来,则E值为每个连通块的横坐标种数 * 纵坐标种数之和。

线段树分治 + 可回退化并查集,O(nlog2n)。

 #include <bits/stdc++.h>

 typedef long long LL;
const int N = ; struct Node {
int x, y;
Node(int X, int Y) {
x = X;
y = Y;
}
}; std::map<int, int> mp[N];
int n, m;
LL ans[N];
std::vector<Node> v[N << ]; namespace ufs { struct opt {
int x, y;
opt(){}
opt(int X, int Y) {
x = X, y = Y;
}
}stk[N * ]; int top; int fa[N * ], siz[N * ], s1[N * ], s2[N * ], clock;
LL tot, stk2[N];
inline void init() {
for(int i = ; i < N; i++) {
fa[i] = i;
fa[i + N] = i + N;
siz[i] = siz[i + N] = ;
s1[i] = s2[i + N] = ;
s2[i] = s1[i + N] = ;
}
top = clock = ;
return;
}
int find(int x) {
if(x == fa[x]) return x;
return find(fa[x]);
}
inline LL cal(int x) {
return 1ll * s1[x] * s2[x];
}
inline void merge(int x, int y) {
x = find(x);
y = find(y);
if(x == y) return;
if(siz[x] < siz[y]) {
std::swap(x, y);
}
stk2[++clock] = tot;
tot -= cal(x) + cal(y);
stk[++top] = opt(y, fa[y]);
fa[y] = x;
stk[++top] = opt(x, siz[x]);
siz[x] += siz[y];
stk[++top] = opt(x, s1[x]);
s1[x] += s1[y];
stk[++top] = opt(x, s2[x]);
s2[x] += s2[y];
tot += cal(x);
return;
}
inline void erase(int t) {
while(clock > t) {
tot = stk2[clock--];
s2[stk[top].x] = stk[top].y;
top--;
s1[stk[top].x] = stk[top].y;
top--;
siz[stk[top].x] = stk[top].y;
top--;
fa[stk[top].x] = stk[top].y;
top--;
}
return;
}
} void add(int L, int R, Node x, int l, int r, int o) {
if(L <= l && r <= R) {
v[o].push_back(x);
return;
}
int mid = (l + r) >> ;
if(L <= mid) {
add(L, R, x, l, mid, o << );
}
if(mid < R) {
add(L, R, x, mid + , r, o << | );
}
return;
} void solve(int l, int r, int o) {
int now = ufs::clock;
for(int i = ; i < (int)v[o].size(); i++) {
ufs::merge(v[o][i].x, v[o][i].y + N);
//printf("[%d %d] merge %d %d \n", l, r, v[o][i].x, v[o][i].y);
}
if(l == r) {
ans[r] = ufs::tot;
ufs::erase(now);
return;
}
int mid = (l + r) >> ;
solve(l, mid, o << );
solve(mid + , r, o << | );
ufs::erase(now);
return;
} int main() {
ufs::init();
scanf("%d", &n);
for(int i = , x, y; i <= n; i++) {
scanf("%d%d", &x, &y);
if(mp[x][y]) {
add(mp[x][y], i - , Node(x, y), , n, );
//printf("add : (%d %d) [%d %d] \n", x, y, mp[x][y], i - 1);
mp[x][y] = ;
}
else {
mp[x][y] = i;
}
}
std::map<int, int>::iterator it;
for(int i = ; i < N; i++) {
for(it = mp[i].begin(); it != mp[i].end(); it++) {
if(it->second) {
add(it->second, n, Node(i, it->first), , n, );
//printf("add : (%d %d) [%d %d] \n", i, it->first, it->second, n);
}
}
} solve(, n, );
for(int i = ; i <= n; i++) {
printf("%lld ", ans[i]);
}
return ;
}

AC代码

CF1140F - Extending Set of Points的更多相关文章

  1. CF1140F Extending Set of Points 【按时间分治,并查集】

    题目链接:洛谷 首先我们考虑没有撤回操作的情况,就是将每一行和每一列看做一个点(代表行的称为白点,代表列的称为黑点),每个点$(x,y)$看做一条边. Extend操作实际上就是$x_1$行与$y_1 ...

  2. Codeforces 1140F Extending Set of Points 线段树 + 按秩合并并查集 (看题解)

    Extending Set of Points 我们能发现, 如果把x轴y轴看成点, 那么答案就是在各个连通块里面的x轴的个数乘以y轴的个数之和. 然后就变成了一个并查集的问题, 但是这个题目里面有撤 ...

  3. Codeforces 1140F Extending Set of Points (线段树分治+并查集)

    这题有以下几个步骤 1.离线处理出每个点的作用范围 2.根据线段树得出作用范围 3.根据分治把每个范围内的点记录和处理 #include<bits/stdc++.h> using name ...

  4. Educational Codeforces Round 62 (Rated for Div. 2) Solution

    最近省队前联考被杭二成七南外什么的吊锤得布星,拿一场Div. 2恢复信心 然后Div.2 Rk3.Div. 1+Div. 2 Rk9,rating大涨200引起舒适 现在的Div. 2都怎么了,最难题 ...

  5. Embeding Python & Extending Python with FFPython

    Introduction ffpython is a C++ lib, which is to simplify tasks that embed Python and extend Python. ...

  6. (转) Written Memories: Understanding, Deriving and Extending the LSTM

    R2RT   Written Memories: Understanding, Deriving and Extending the LSTM Tue 26 July 2016 When I was ...

  7. [转]Extending the User Interface in Outlook 2010

    本文转自:https://msdn.microsoft.com/en-us/library/office/ee692172%28v=office.14%29.aspx#OfficeOLExtendin ...

  8. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  9. [LeetCode] Max Points on a Line 共线点个数

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

随机推荐

  1. Flink on YARN(下):常见问题与排查思路

    Flink 支持 Standalone 独立部署和 YARN.Kubernetes.Mesos 等集群部署模式,其中 YARN 集群部署模式在国内的应用越来越广泛.Flink 社区将推出 Flink ...

  2. thinkphp present标签

    present标签用于判断某个变量是否已经定义,用法: 大理石平台精度等级 <present name="name"> name已经赋值 </present> ...

  3. 0927CSP-S模拟测试赛后总结

    84pts rank28 经历了一个阶段的持续低迷,终于回到自己之前的位置了啊. 尽管依旧不是太靠上,但是还是证明了我的努力. 宿舍三人的风水轮流转之谈终究只是戏言和巧合.嘟嘟和Lockey都进第一机 ...

  4. 2816: [ZJOI2012]网络

    传送们 把一个点拆成c个即可 浪费时间的水题... //Achen #include<algorithm> #include<iostream> #include<cst ...

  5. go包flag系统包简单使用

    一.代码 package main import ( "flag" "fmt" ) //定义命令行参数,这个mode是内存地址,参数1是命令行名称,参数2是命令 ...

  6. (1)python tkinter-窗体

    1.导入自带的包名 import tkinter 2.创建一个窗体对象 form=Tkinter.Tk() 3.显示窗体(这句应该是所有的设置部署完最后执行的一句代码) form.mainloop() ...

  7. Python编码decode和encode

    常见编码介绍: GB2312编码:适用于汉字处理.汉字通信等系统之间的信息交换;GBK编码:是汉字编码标准之一,是在 GB2312-80 标准基础上的内码扩展规范,使用了双字节编码ASCII编码:是对 ...

  8. 模板方法模式&策略模式区别联系

    一.模板方法 模板方法模式:定义 一系列算法, 子类延伸实现.着重点在于:子类去处理不同的方法实现. 看下面例子. 假如一个支付 都包含三个部分: 生成订单 ---->调用API发起支付---- ...

  9. 按指定规则统计list中数据,groupby用法

    有的情况下,只是想要简单地对list中数据,进行分组,查看,可以考虑使用groupby 代码: # groupby需要排序后才能使用 def gb(num): if 0 <= num < ...

  10. Ifconfig- Linux必学的60个命令

    1.作用 ifconfig用于查看和更改网络接口的地址和参数,包括IP地址.网络掩码.广播地址,使用权限是超级用户. 2.格式 ifconfig -interface [options] addres ...