随笔分类 - 模板
摘要:E. Lomsat gelral 注意答案会爆int 点击查看代码 #include<bits/stdc++.h> using namespace std; const int N=1e5+10; #define LL long long LL w[N];//w int n,q; vector<in
阅读全文
摘要:U41492 树上数颜色 点击查看代码 #include<bits/stdc++.h> using namespace std; const int N=1e5+10; int w[N];//w vector<int> g[N]; vector<int>qr[N]; int ans[N]; int
阅读全文
摘要:小蓝的疑问【算法赛】 点击查看代码 #include<bits/stdc++.h> using namespace std; const int N=1e5+10; int w[N];//w vector<int> g[N]; vector<pair<int,int> >qr[N]; int ans
阅读全文
摘要:神奇数 点击查看代码 #include <bits/stdc++.h> using namespace std; const int N=250,mod=998244353; int f[N][2000];//长度为i时,前pos-1项的和为j的合法数 string s; //pos位置,sum==
阅读全文
摘要:bfs 点击查看代码 #include<bits/stdc++.h> using namespace std; const int N=1e5+10; #define LL long long int cnt,h[N],to[N*2],w[N*2],ne[N*2]; void add(int a,i
阅读全文
摘要:P1892 [BOI2003] 团伙 如果你wa,可能是合并的顺序出错 [1,n]表示朋友,[n+1,2*n]表示敌人 如果a,b是朋友,直接合并a,b 如果a,b是敌人: 1.合并a+n和b,a的敌人是b的朋友 2.合并a和b+n,b的敌人是a的朋友 点击查看代码 #include<bits/st
阅读全文
摘要:降雨量 可以利用线段树,st表 模板+模拟 思路: 1.利用st表,先算出每个区间内的最大值 2.模拟: 2.1因为true要求的条件更加苛刻,所以先对true分析: 1.两端年份存在 2.年份连续 3.俩年份内的最大值小于右端 4.左端降雨量小于等于右端 2.2 对false分析: 1.特判:如果
阅读全文
摘要:P3865 【模板】ST 表 利用倍增 f[i][j]表示,范围[i,i+2^(j)-1]内的最大值是多少 点击查看代码 #include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int f[N][22]; int ma
阅读全文
摘要:推荐视频:模意义下的乘法逆元 特点:除以一个数取模等于乘以这个数的逆元取模:a/n%mod==a* n^(mod-2)%mod(费马小定理) 1.费马小定理 前提:p为质数 n的逆元等于n^(p-2) 点击查看代码 #include<bits/stdc++.h> using namespace st
阅读全文
摘要:P3901 数列找不同 莫队:一种离线处理的优化暴力解法,时间复杂度在n * n^(1/2),会被卡常数,但是极为简单 推荐视频:莫队算法 点击查看代码 #include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int
阅读全文
摘要:原文链接:https://blog.csdn.net/qq_43227036/article/details/100336234 OK,前面已经讲了很多判断素数的方法,在判断一个数是否为素数时我们可以采用试除法,但如要求1-n的范围那么时间复杂度很高,所以有了线性的筛法求素数。 但如果为了判断一个大
阅读全文
摘要:推荐视频:518 筛法求莫比乌斯函数 前提知识:莫比乌斯函数 点击查看代码 #include<bits/stdc++.h> using namespace std; #define LL long long const int N = 1e8 + 10; int p[N], cnt; int mu[
阅读全文
摘要:推荐视频:517 筛法求约数和 这个比较简单,若想来点挑战,请点开这个:P2424 约数和 点击查看代码 #include<bits/stdc++.h> using namespace std; #define LL long long const int N = 1e8 + 10; int p[N
阅读全文
摘要:推荐视频:516 筛法求约数个数 点击查看代码 #include<bits/stdc++.h> using namespace std; #define LL long long const int N = 1e8 + 10; int p[N], cnt; int d[N];//d[i]记录i的约数
阅读全文
摘要:筛法+试除 推荐视频:筛法求欧拉函数 点击查看代码 #include<bits/stdc++.h> using namespace std; #define LL long long const int N = 1e8 + 10; int p[N], cnt,phi[N]; bool vis[N];
阅读全文
摘要:点击查看代码 void write(int x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); return; }
阅读全文
摘要:整数 点击查看代码 ``` int read() { int x=0,f=1; char ch=getchar(); while(ch'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch 字符串 点击查看代码 inline stri
阅读全文
摘要:【模板】线性筛素数 点击查看代码 #include<bits/stdc++.h> using namespace std; #define LL long long const int N = 1e8 + 10; int p[N],cnt,vis[N]; int main() { ios::sync
阅读全文
摘要:因为n是两个质数的乘积,所以直接暴力枚举,只要能被整除,直接输出 因为是要求大的那个,所以从小到大枚举,输出商即可 点击查看代码 #include<bits/stdc++.h> using namespace std; #define LL long long int main() { LL n;
阅读全文
浙公网安备 33010602011771号