摘要: 我的洛谷主页:decentz (发的模板方便自己用) 好用的luogu插件:luogu自定义背景板、主页显示收藏题单 其他: 折叠代码块: 点我展开看代码 咕咕咕~ this: <details> <summary>点我展开看代码</summary> 空行 cpp 空行 </details> 阅读全文
posted @ 2026-08-08 11:50 decentz 阅读(16) 评论(0) 推荐(0)
摘要: 构造题 1.题目(K) 简略题意:构造一个长度为n的排列,要求 \(\left | p_{i}-p_{ i \bmod n +1} \right |\) 为质数。不保证有解,\(2\le n\le 1e5\)。 思路 首先,我们已知题目要求使排列中所有相邻差的绝对值为质数。 因为质数中最常见且容易构 阅读全文
posted @ 2026-08-18 14:02 decentz 阅读(28) 评论(0) 推荐(0)
摘要: 题目 离线二维数点模板 时间复杂度:\(O((n+m)\log V)\),(\(V\) 是值域大小) #include<bits/stdc++.h> using namespace std; const int N=2e6+5; int n,m,a[N],tr[N],ans[N];//a:原序列,t 阅读全文
posted @ 2026-08-18 07:38 decentz 阅读(11) 评论(0) 推荐(0)
摘要: 线段树(1~2)模板 题目 线段树1: 时间复杂度:\(O(n+m\log n)\) #include<bits/stdc++.h> #define lc p<<1 //左儿子编号 #define rc p<<1|1 //右儿子编号 using namespace std; const int N= 阅读全文
posted @ 2026-08-17 08:04 decentz 阅读(9) 评论(0) 推荐(0)
摘要: 题目 前缀和+记忆化搜索的方法: 时间复杂度:\(O(10^{2} L^{2})\)(\(L\)为数字位数) #include<bits/stdc++.h> using namespace std; long long a,b,f[25][25],dig[20];//f[pos][k]:记忆化数组, 阅读全文
posted @ 2026-08-16 14:52 decentz 阅读(21) 评论(0) 推荐(0)
摘要: 全源最短路模板 题目 Johnson: 时间复杂度:\(O(nm+n(n+m)\log n)\) #include<bits/stdc++.h> using namespace std; using pii=pair<long long,int>; const int N=5005,INF=1e9; 阅读全文
posted @ 2026-08-15 14:22 decentz 阅读(13) 评论(0) 推荐(0)
摘要: 题目 最小生成树模板 Kruskal: 时间复杂度:\(O(M\log M)\) #include<bits/stdc++.h> using namespace std; int N,M,f[5010],ans; struct node{ int X,Y,Z; }e[200010]; bool cm 阅读全文
posted @ 2026-08-15 10:39 decentz 阅读(8) 评论(0) 推荐(0)
摘要: 题目 最近公共祖先模板 DFS序求LCA 时间复杂度:\(O(N\log N+M)\) #include<bits/stdc++.h> using namespace std; const int MAXN=5e5+5; int N,M,S,cnt,dfn[MAXN],st[20][MAXN],lg 阅读全文
posted @ 2026-08-14 09:46 decentz 阅读(11) 评论(0) 推荐(0)
摘要: 题目 差分约束模板 时间复杂度:\(O(nm)\) #include<bits/stdc++.h> using namespace std; const int N=5005; int n,m,hd[N],ver[2*N],nxt[2*N],w[2*N],tot,dis[N],cnt[N]; boo 阅读全文
posted @ 2026-08-12 19:06 decentz 阅读(10) 评论(0) 推荐(0)
摘要: 题目 负环模板 时间复杂度:\(O(Tnm)\) #include<bits/stdc++.h> using namespace std; const int N=3005; int T,n,m,hd[N],ver[2*N],nxt[2*N],w[2*N],tot,dis[N],cnt[N];//c 阅读全文
posted @ 2026-08-12 11:52 decentz 阅读(9) 评论(0) 推荐(0)
摘要: 一些简单的模板 快速幂模板 题目 时间复杂度:\(O(\log b)\) #include<bits/stdc++.h> using namespace std; long long a,b,p; long long qp(long long a,long long b,long long p){ 阅读全文
posted @ 2026-08-11 18:36 decentz 阅读(7) 评论(0) 推荐(0)
摘要: 题目 单源最短路径模板 Dijkstra: 时间复杂度:\(O((n+m)\log n)\) #include<bits/stdc++.h> using namespace std; using pii=pair<long long,int>; const int N=1e5+10; int n,m 阅读全文
posted @ 2026-08-11 07:41 decentz 阅读(8) 评论(0) 推荐(0)
摘要: 题目 树同构模板(树哈希) 时间复杂度:\(O(MN\log N)\) #include<bits/stdc++.h> using namespace std; const int MAXN=55; const int mod=1e9+7,base=19491001;//模数(防止哈希值溢出);基数 阅读全文
posted @ 2026-08-10 21:52 decentz 阅读(10) 评论(0) 推荐(0)
摘要: 题目 笛卡尔树模板 时间复杂度:\(O(n)\) #include<bits/stdc++.h> using namespace std; const int N=1e7+10; int n,p[N],stk[N]; long long ql,qr,l[N],r[N]; void build(){/ 阅读全文
posted @ 2026-08-09 19:34 decentz 阅读(15) 评论(0) 推荐(0)
摘要: 题目 单调栈模板 时间复杂度:\(O(n)\) #include<bits/stdc++.h> using namespace std; const int N=3e6+5; int n,a[N],f[N]; stack<int> s; int main(){ ios::sync_with_stdi 阅读全文
posted @ 2026-08-09 07:58 decentz 阅读(12) 评论(0) 推荐(0)