摘要: 我的洛谷主页:decentz (发的模板方便自己用) 好用的luogu插件:luogu自定义背景板、主页显示收藏题单 其他: 折叠代码块: 点我展开看代码 咕咕咕~ this: <details> <summary>点我展开看代码</summary> 空行 cpp 空行 </details> 阅读全文
posted @ 2026-08-08 11:50 decentz 阅读(25) 评论(0) 推荐(0)
摘要: 题目 Manacher模板 时间复杂度:\(O(n)\) #include<bits/stdc++.h> using namespace std; const int N=1.1e7+5; string s; char dt[N<<1]; int p[N<<1],ans,cnt;//注意p是指半径 阅读全文
posted @ 2026-10-28 19:52 decentz 阅读(4) 评论(0) 推荐(0)
摘要: 题目 KMP模板 时间复杂度:\(O(n+m)\) #include<bits/stdc++.h> using namespace std; const int N=1e6+5; string p,s; int nxt[N]; void kmp(){ for(int i=2,j=0;i<=p.siz 阅读全文
posted @ 2026-10-28 19:00 decentz 阅读(6) 评论(0) 推荐(0)
摘要: 题目 洛谷 题意 每次询问一条边 \(x\),然后假设把这条边删掉,看看还能不能从 \(1\) 走到 \(n\),能走到,就真删掉,输出 \(1\);不能走到,就保留这条边,输出 \(0\)。注意,成功删掉的边,以后就一直不存在了。 思路 根据题意,我们思考,假如我们能提前确定一条从 \(1\) 到 阅读全文
posted @ 2026-10-23 20:40 decentz 阅读(8) 评论(0) 推荐(0)
摘要: 题目 题意 树上有一些标记为 \(1\) 和 \(0\) 的点(下文我们将其分别称作黑点和白点)。 每次必须选两个黑点配对,代价是它们之间的树上距离。一个点配对后就不能再使用。 在开始之前,还可以交换两个点的权值。就是相当于:把一个黑点移动到一个原本是白点的位置,然后也可以选择不交换。 目标是让所有 阅读全文
posted @ 2026-10-21 19:44 decentz 阅读(6) 评论(1) 推荐(0)
摘要: P2919 简要题意: 给定一个 \(N\times M\) 的矩阵,每个元素 \(H_{ij}\) 表示高度,求有多少个山顶。一个山顶由一个或多个相邻且具有相同值的矩阵元素组成,这些元素被地图的边缘或具有较低(较小)高度的元素完全包围。 思路 其实就是遍历整张图,没有访问过的就 \(BFS\) 去 阅读全文
posted @ 2026-10-02 21:12 decentz 阅读(30) 评论(1) 推荐(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 阅读(55) 评论(1) 推荐(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 阅读(23) 评论(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 阅读(25) 评论(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 阅读(28) 评论(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 阅读(22) 评论(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 阅读(18) 评论(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 阅读(18) 评论(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 阅读(18) 评论(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 阅读(17) 评论(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 阅读(11) 评论(0) 推荐(0)