#121. 「离线可过」动态图连通性 (线段树分治)

该博客探讨了一种离线处理动态图连通性问题的方法,利用线段树分治策略。通过线段树维护按秩合并的可撤销并查集,可以在O(n log^2 n)的时间复杂度内解决包含多个时间段操作和时间点询问的问题。文章提供了详细的题解和代码实现。
摘要由CSDN通过智能技术生成

题目链接

题面:
在这里插入图片描述
题解:
线段树分治。
(1)有一些操作,每个操作只在 l − r l-r lr 的时间段内有效。
(2)有一些询问,每个询问询问某一个时间点所有操作的贡献。

离线,时间线段树上维护按秩合并可撤销并查集。
时间复杂度 O ( n l o g 2 n ) O(nlog^2n) O(nlog2n)

代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<list>
#include<ctime>
#define ui unsigned int
#define ll long long
#define llu unsigned ll
#define ld long double
#define pr make_pair
#define pb push_back
#define lc (cnt<<1)
#define rc (cnt<<1|1)
#define len(x)  (t[(x)].r-t[(x)].l+1)
#define tmid ((l+r)>>1)
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
using namespace std;

const int inf=0x3f3f3f3f;
const ll lnf=0x3f3f3f3f3f3f3f3f;
const double dnf=1e18;
const int mod=1e9+7;
const double eps=1e-1;
const double pi=
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值