LOJ #109. 并查集】的更多相关文章

题目描述 这是一道模板题. 维护一个 n 点的无向图,支持: 加入一条连接 u 和 v 的无向边 查询 u 和 v 的连通性 由于本题数据较大,因此输出的时候采用特殊的输出方式:用 0 或 1 代表每个询问的答案,将每个询问的答案依次从左到右排列,把得到的串视为一个二进制数,输出这个二进制数 mod 998244353 的值. 分析 简单的并查集. AC代码 #include <bits/stdc++.h> using namespace std; const int maxn=8000005…
内存限制:256 MiB时间限制:2000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论 1 测试数据   题目描述 这是一道模板题. 维护一个 nnn 点的无向图,支持: 加入一条连接 uuu 和 vvv 的无向边 查询 uuu 和 vvv 的连通性 由于本题数据较大,因此输出的时候采用特殊的输出方式:用 000 或 111 代表每个询问的答案,将每个询问的答案一次从左到右排列,把得到的串视为一个二进制数,输出这个二进制数 mod 998244353…
题目描述 这是一道模板题. 维护一个 nnn 点的无向图,支持: 加入一条连接 uuu 和 vvv 的无向边 查询 uuu 和 vvv 的连通性 由于本题数据较大,因此输出的时候采用特殊的输出方式:用 000 或 111 代表每个询问的答案,将每个询问的答案一次从左到右排列,把得到的串视为一个二进制数,输出这个二进制数 mod 998244353\text{mod} ~ 998244353mod 998244353 的值. 输入格式 第一行包含两个整数 n,mn,mn,m,表示点的个数和操作的数…
[LOJ#3145][APIO2019]桥梁(分块,并查集) 题面 LOJ 题解 因为某个\(\text{subtask}\)没判\(n=1\)的情况导致我自闭了很久的题目... 如果没有修改操作,可以克鲁斯卡尔重构树在线处理.或者按照边权排序离线并查集处理. 现在有修改操作,于是我们来分块. 我们对于操作分块,每\(B\)个操作作为一组处理.不同组之间显然影响不大. 所以我们只需要处理同一组的就好了. 把边分成两类,一类是不会被修改的,这些边直接排序做前面的并查集就好了,这部分复杂度是\(O(…
LOJ 508 失控的未来交通工具 (带权并查集 + 数论) $ solution: $ 很综合的一道难题.看了让人不知所措,数据范围又大,题目描述又不清晰.只能说明这道题有很多性质,或者很多优化. 好了,回来讲正解.像这种在图上寻找路径,并且对路径取模,尤其还不是简单路径的题,基本上都和环的性质有关.因为环我们可以无限跑啊!而这一道题在环上路径长度取模,需要联系到一个结论(就是天天爱跑步):我可以加一个数 $ w $ 无限次,得到的数要对 $ m $ 取模,那么我最终能且仅能得到所有小于 $…
[APIO2019] [LOJ 3145] 桥梁(分块+并查集)(有详细注释) 题面 略 分析 考试的时候就感觉子任务4是突破口,结果却写了个Kruskal重构树,然后一直想怎么在线用数据结构维护 实际上是离线算法.考虑只有查询的时候.我们可以离线对查询的权值从大到小排序,边也按边权从大到小排序,然后对于权值比询问大的边,把边两端结点集合合并.答案就是查询点所在点集的大小.只需要用并查集维护,然后双指针扫描,由于一条边只会被加进去一次,时间复杂度为$ O(n\log n)$ 考虑有修改的情况.所…
题目描述 一个点每过一个单位时间就会向 444 个方向扩散一个距离,如图所示:两个点 a .b 连通,记作 e(a,b),当且仅当 a .b的扩散区域有公共部分.连通块的定义是块内的任意两个点 u.v都必定存在路径 e(u,a0),e(a0,a1),…e(ak,v). 给定平面上的 n 个点,问最早什么时候它们形成一个连通块. 输入格式 第一行一个数 nnn ,以下 nnn 行,每行一个点坐标. 输出格式 输出仅一个数,表示最早的时刻所有点形成连通块. 样例 样例输入 2 0 0 5 5 样例输…
题意 你要维护一张\(n\)个点的无向简单图.你被要求执行\(m\)条操作,加入删除一条边及查询两个点是否连通. 0:加入一条边.保证它不存在. 1:删除一条边.保证它存在. 2:查询两个点是否联通. \(n \leq 5\times 10^3, m \leq 5\times 10^5\) 题解 第一次写按时间分治的题,感觉还是比较 清新 有趣的 对时间建线段树,一个结点\([l, r]\)上存储在时间\([l, r]\)上存在的边集,那么询问在叶子结点上 对这颗线段树\(dfs\),我们到一个…
把 $Noi2018$ day1t1 想出来还是挺开心的,虽然是一道水题~ 预处理出来 1 号点到其它点的最短路,然后预处理边权从大到小排序后加入前 $i$ 个边的并查集. 这个并查集用可持久化线段树维护可持久化数组来完成. 每次询问时在边集上二分一下,找到对应的并查集,然后找到祖先并输出极小值即可. #include <bits/stdc++.h> #define N 400005 #define ll long long #define setIO(s) freopen(s".i…
题面 点此看题 题意很明白,就不转述了吧. 题解 题目相当于告诉了我们若干等量关系,每个限制 l 1 , r 1 , l 2 , r 2 \tt l_1,r_1,l_2,r_2 l1​,r1​,l2​,r2​ 相当于 S l 1 = S l 2 , S l 1 + 1 = S l 2 + 1 , - , S r 1 = S r 2 \tt S_{l_1}=S_{l_2},S_{l_1+1}=S_{l_2+1},\dots,S_{r_1}=S_{r_2} Sl1​​=Sl2​​,Sl1​+1​=S…
链接:Destroying Array C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array consisting of n non-negative integers a1, a2, ..., an. You are going to destro…
Codeforces Round #268 (Div. 2)D Codeforces Round #268 (Div. 1)B CF468B D. Two Sets time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little X has n distinct integers: p1, p2, ..., pn. He want…
D. Fools and Foolproof Roads   You must have heard all about the Foolland on your Geography lessons. Specifically, you must know that federal structure of this country has been the same for many centuries. The country consists of n cities, some pairs…
A. Arpa’s hard exam and Mehrdad’s naive cheat time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Me…
D. Dividing Kingdom II   Long time ago, there was a great kingdom and it was being ruled by The Great Arya and Pari The Great. These two had some problems about the numbers they like, so they decided to divide the great kingdom between themselves. Th…
A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format…
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya encountered a tre…
E. Bindian Signalizing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/5/E Description Everyone knows that long ago on the territory of present-day Berland there lived Bindian tribes. Their capital was surrounded…
题目链接: 题目 F. Polycarp and Hay time limit per test: 4 seconds memory limit per test: 512 megabytes input: standard input output: standard output 问题描述 The farmer Polycarp has a warehouse with hay, which can be represented as an n × m rectangular table,…
C. Table Compression Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and many others. Inspired by the new knowledge, Petya is now developing the new compression algorithm which he wants to name d…
Luogu 2245 星际导航(最小生成树,最近公共祖先LCA,并查集) Description sideman做好了回到Gliese 星球的硬件准备,但是sideman的导航系统还没有完全设计好.为了方便起见,我们可以认为宇宙是一张有N 个顶点和M 条边的带权无向图,顶点表示各个星系,两个星系之间有边就表示两个星系之间可以直航,而边权则是航行的危险程度. sideman 现在想把危险程度降到最小,具体地来说,就是对于若干个询问(A, B),sideman 想知道从顶点A 航行到顶点B 所经过的…
C. Edgy Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a tree (a connected undirected graph without cycles) of nn vertices. Each of the n−1n−1 edges of the tree is col…
题目传送门 需要root权限的传送门 题目大意 有一个$n\times m$的网格图,每一格都有一个高度.一次降雨过后问最多能积多少水. 考虑算每一高度能储存的水的量. 如果小于等于这个高度的格子和边界连通,那么水就会流走,这一部分不能算入答案. 所以用并查集维护高度小于等于当前高度的格子的连通性.每次答案加已经找到的格子数目减去和边界连通的格子数. 时间复杂度$O(nm + V)$.(当我再写一个并查集按秩合并就是这样的) 网上咋一群带个$log$的做法.想去loj出个加强版. Code /*…
C. Destroying Array 题目连接: http://codeforces.com/contest/722/problem/C Description You are given an array consisting of n non-negative integers a1, a2, ..., an. You are going to destroy integers in the array one by one. Thus, you are given the permuta…
题目:http://uoj.ac/problem/393 题解:https://www.cnblogs.com/HocRiser/p/9368067.html 但过不了 UOJ 的 hack 数据.不知道是哪里出错.之后再管吧. #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<queue> #define mkp make_pair…
http://acm.uestc.edu.cn/#/problem/show/203 Islands Time Limit: 30000/10000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit Status Deep in the Carribean, there is an island even stranger than the Monkey Island, dwelled by Horatio…
D. Dividing Kingdom II 题目连接: http://www.codeforces.com/contest/687/problem/D Description Long time ago, there was a great kingdom and it was being ruled by The Great Arya and Pari The Great. These two had some problems about the numbers they like, so…
题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secondsmemory limit per test256 megabytes 问题描述 Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and m…
F. Polycarp and Hay 题目连接: http://www.codeforces.com/contest/659/problem/F Description The farmer Polycarp has a warehouse with hay, which can be represented as an n × m rectangular table, where n is the number of rows, and m is the number of columns…
islands Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/problem/show/1385 Description Deep in the Carribean, there is an island even stranger than the Monkey Island, dwelled by Horatio Torquemada Marley. Not only it has a rectangu…