随笔分类 - 算法竞赛
摘要:https://codeforces.com/contest/1605/problem/D 读了个假题 Codeforces - 1603C - Extreme Extension 原题链接:https://codeforces.com/contest/1603/problem/C 官方的题解相对难
阅读全文
摘要:昨天看群里讨论哈希使用自然溢出被卡的问题,突然想到一个问题,就是为什么需要使用双模去做字符串哈希才能有效保证正确率呢? 把n个元素放进m个桶里面,不发生冲突的概率: \(P = e^{\frac{-n(n-1)}{2m})\) 求解这个式子可以得知,要求正确率达到1e-9级别的话,m大概需要n的平方
阅读全文
摘要:/* MOD must be a prime. if not, don't use inv() */ const int MOD = 1e9 + 7; struct ModularIntegers { #define mint ModularIntegers int num; mint() { nu
阅读全文
摘要:const int MAXN = 2e5 + 10; int a[MAXN]; int val[MAXN]; #define mid ((l + r)>>1) int L[MAXN << 5]; int R[MAXN << 5]; int cnt[MAXN << 5]; ll sum[MAXN <<
阅读全文
摘要:https://codeforces.com/gym/102900/problem/C 找数对(x,y),他们的二进制位与的结果一定是0,然后他们的贡献就是他们位或的msb的长度+1。 状态为dp[dep][xlim][ylim][lzero]表示长度为dep的数对,x限制为xlim,y限制为yli
阅读全文
摘要:一种节约空间的内存写法: static constexpr int calc_segment_tree_size (int n) { int res = 1; while (res < (n << 1)) { res <<= 1; } return res; } static constexpr i
阅读全文
摘要:退役记 整个XCPC,从2017年10月买了第一本书《挑战程序设计竞赛》开始,一直学到参加2021年4月ICPC昆明站为止,历时3.5年的超长XCPC生涯终于结束了。整个大学生活除了XCPC真的几乎什么都不剩下了(可能唯一是2020年6月到9月摸鱼去腾讯参加了一段实习吧)。在退役的一场拿到了第一个也
阅读全文
摘要:https://codeforces.com/contest/1923/problem/E 这一道题有三种不一样的写法,有一种是用启发式合并(跟树上没啥关系)去优化dp的做法。 int n, k; int c[200005]; vector<int> G[200005]; ll ans; map<i
阅读全文
摘要:CF375D - Tree and Queries 题意:给定一棵 \(n(2\leq n\leq 10^5)\) 个结点的树,根结点为 \(1\) 号结点,每个结点有颜色 \(c(\leq c\leq 10^5)\) 。然后 \(m(1\leq m\leq 10^5)\) 次询问,每次询问给两个参
阅读全文
摘要:给一棵n个节点的树,覆盖m条树链,统计每个顶点和每条边被覆盖了多少次。 dfs1:标记深度、子树大小、找重儿子 dfs2:轻重链剖分 chain:覆盖一条树链 calc:统计每个顶点和每条边被覆盖了多少次 const int MAXN = 3e5 + 5; int n, m; vector<int>
阅读全文
摘要:简易的多项式。用来粗暴模拟。 struct Poly { static const int MAXN = 1e3 + 10; int deg, f[MAXN]; Poly() { deg = 0, memset(f, 0, sizeof(f)); } int& operator[](int inde
阅读全文
摘要:复杂度确定的分治算法(还带有一个最优性剪枝) const int MAXN = 2e5 + 10; const double MAXDIS = 1e20; int n; struct Point { double x, y; } p[MAXN]; double calc(int l, int r,
阅读全文
摘要:https://codeforces.com/contest/1239/problem/C 人为规定事件的优先级 永续事件用个触发器触发 int n; ll p; ll ans[100005]; struct Event { ll Time; int Type, Id; bool operator<
阅读全文
摘要:使得队列可以快速求解出队列中的某些值,使用于没有逆元(最大最小值)或者逆元很难求(矩阵的逆(有时不存在))。 struct MinQueue { stack<pii> F; stack<pii> B; int Min() { int res = INF; if (!F.empty()) res =
阅读全文
摘要:匈牙利算法,优点:代码短 邻接矩阵:复杂度 \(O(n^3)\) 。邻接表:复杂度 \(O(nm)\) 。 /* nx X侧顶点的数量 ny Y侧顶点的数量 vis 顶点i是否在交错路中 cx X侧顶点i匹配的Y侧顶点 cy Y侧顶点i匹配的X侧顶点 */ const int MAXN = 500
阅读全文
摘要:期望复杂度 \(O(n)\) const double PI = acos(-1.0); const double EPS = 1e-10; double sqr(double x) { return x * x; } struct Point { double x, y; }; struct Ci
阅读全文
摘要:https://codeforces.com/contest/320/problem/E 斜率优化dp https://codeforces.com/contest/631/problem/E 单调栈维护一个决策凸包,二分。 int n; ll a[200005]; ll sum[200005];
阅读全文
摘要:https://codeforces.com/contest/1281/problem/F 题意:每个顶点有两个权值b和w。最多3000个节点的树,分成恰好m个非空的连通块,使得尽可能多的连通块满足w的和严格大于b的和。 树上背包的套路题,这里背包 \(dp[i][j]\) 表示以i为根的子树,已经
阅读全文

浙公网安备 33010602011771号