摘要: 前置知识: 容斥原理(可参考https://www.cnblogs.com/komet/p/15156521.html), 互质概念, 基础数学。 欧拉函数 φ(n) 定义为对正整数n,小于n的正整数中与n互质的数的数目。 通项公式为: 公式1 先不考虑欧拉函数具体是什么,我们先考虑它的定义——小于 阅读全文
posted @ 2021-09-20 15:01 _comet 阅读(260) 评论(0) 推荐(1) 编辑
摘要: struct seg { int l, r; int flag; int id; }s[N]; int split(int x, int y) { int cnt = 0; int flag=0; int fx = top[x], fy = top[y]; while (fx != fy) { if 阅读全文
posted @ 2021-09-13 20:26 _comet 阅读(25) 评论(0) 推荐(1) 编辑
摘要: #include<iostream> #include<algorithm> #include<cmath> #include<cstdio> #include<queue> #include<cstring> #include<ctime> #include<string> #include<ve 阅读全文
posted @ 2021-08-25 20:57 _comet 阅读(58) 评论(0) 推荐(0) 编辑
摘要: vector<int>e[N]; int w[N], dfn[N], subsize[N], fa[N], dep[N], wson[N], top[N]; int tol; int v[N]; int R[N]; void dfs1(int x, int f) { subsize[x] = 1; 阅读全文
posted @ 2021-08-25 20:56 _comet 阅读(20) 评论(0) 推荐(0) 编辑
摘要: 根据二项式定理有 得 这个公式配合容斥可以解决区间互质问题。 在考虑两个区间互质的情况之前我们先考虑它的一个子问题,一个数x与一个区间[l,r]的互质问题。 处理这个问题,最简单的方法肯定是遍历区间,复杂度为O(n),n为区间长度,显然太慢。 这时我们可以逆向思维,转换问题,我们可以考虑求不互质的个 阅读全文
posted @ 2021-08-18 14:14 _comet 阅读(240) 评论(0) 推荐(0) 编辑
摘要: 询问树上a到b,c到d的两条路径是否相交 如果相交,记 x=lca(a,b),y=lca(c,d),则必有x在c~d路径上或y在a~b路径上若交点是树上最高的交点,并且不是lca,说明这条链向上还有在链上的父节点,两链都不是lca,并且是树上最高的交点,说明,这交点上连接着两条不同的父节点,树不可能 阅读全文
posted @ 2021-08-17 14:54 _comet 阅读(94) 评论(0) 推荐(1) 编辑
摘要: 引言 Tarjan算法的复杂度为O(V+E) Tarjan算法是一个基于深度优先搜索的处理图上连通性问题的算法,可以解决,割边,割点,双连通,强连通等问题。 首先要明白Tarjan算法,首先要知道它能解决的问题的定义。 连通图 无向图 由双向边构成的图称之为无向图。 割点与桥 给定的无向图中删去节点 阅读全文
posted @ 2021-08-16 20:48 _comet 阅读(706) 评论(0) 推荐(2) 编辑
摘要: 题目 题目链接:http://poj.org/problem?id=3177 In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1..F) to another field, 阅读全文
posted @ 2021-08-14 19:04 _comet 阅读(42) 评论(0) 推荐(0) 编辑
摘要: 不同OJ有不同的错误代码,有些OJ没有PE,SE啥的,甚至有没有TLE,RE的OJ,具体的要根据OJ分析,最好比赛前要测试下错误代码的种类,方便赛时找bug。 Wrong Answer :答案错误 输出的答案错误,具体问题各不相同,大概有这几种情况 1.代码哪里写出bug了,代码功能与自己想实现的功 阅读全文
posted @ 2021-08-10 15:12 _comet 阅读(2011) 评论(0) 推荐(1) 编辑
摘要: 题目 链接:https://acm.hdu.edu.cn/showproblem.php?pid=1808 very year there is the same problem at Halloween: Each neighbour is only willing to give a certa 阅读全文
posted @ 2021-08-06 15:23 _comet 阅读(59) 评论(0) 推荐(0) 编辑