摘要: 对于多次询问lca的写法一般有两种…… 第一种是离线lca,把询问存进数组,一次dfs处理出所有答案 对于每一个点,dfs到的时候给他加标记,用一个并查集把遍历完的点连起来。 并且对于遍历到的每个点,遍历一遍在这个点上的询问,假设询问的另一个点已经标记过遍历完了,用并查集往上找最后一个更新的他的祖先 阅读全文
posted @ 2023-01-12 21:56 Reimu222 阅读(80) 评论(0) 推荐(0) 编辑
摘要: #include<bits/stdc++.h> using namespace std; const int N=100005; int a[N]; long long f[N]; bool NotPrime[N]; int Prime[N],mu[N],tot; void sieve(int n) 阅读全文
posted @ 2020-06-07 21:09 Reimu222 阅读(303) 评论(0) 推荐(0) 编辑
摘要: #include<bits/stdc++.h> using namespace std; const int N=1e7+5,mod=20101009; bool NotPrime[N]; int tot; int Prime[N],f[N]; long long pre[N]; void siev 阅读全文
posted @ 2020-06-04 19:20 Reimu222 阅读(203) 评论(0) 推荐(0) 编辑
摘要: #include<bits/stdc++.h> using namespace std; typedef long long LL; const int mod=1000000007; LL PowMod(LL x,LL n) { LL res=1; while(n) { if(n&1) { res 阅读全文
posted @ 2020-06-02 18:03 Reimu222 阅读(139) 评论(0) 推荐(0) 编辑
摘要: ``` void eulershai(int n){ NotPrime[1]=1; phi[1]=1; for(int i=2;i<=n;i++){ if(NotPrime[i]){ Prime[tot++]=i; phi[i]=i-1; } for(int j=0,k;(k=i*Prime[j])<=n;j++){ NotPrime[k]=1; if(i%Prime[j]==0){ phi[k] 阅读全文
posted @ 2020-05-23 20:00 Reimu222 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 一道单调队列的例题 题目链接 poj2823 阅读全文
posted @ 2020-05-03 12:53 Reimu222 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 题目链接:https://vjudge.net/problem/HDU-6030 ; 可以发现每个蓝宝石前必有两个红宝石,因此递推式为fn=fn-1+fn-3; #include<cstdio> using namespace std; typedef long long in; typedef i 阅读全文
posted @ 2019-10-29 20:11 Reimu222 阅读(195) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://www.51nod.com/Challenge/Problem.html#problemId=1134 ; #include<cstdio> #include<algorithm> using namespace std; int f[50005],a[50005]; int 阅读全文
posted @ 2019-10-28 19:02 Reimu222 阅读(312) 评论(0) 推荐(0) 编辑
摘要: 题目链接:https://vjudge.net/problem/HDU-5950 ; #include<iostream> #include<cstdio> using namespace std; typedef long long in; typedef in mat[7][7]; const 阅读全文
posted @ 2019-10-27 18:02 Reimu222 阅读(217) 评论(0) 推荐(0) 编辑