随笔分类 -  算法

摘要:[acwing]4405 .统计子矩阵 #include <cstdio> using namespace std; typedef long long LL; const int N = 510; int n, m, k; int s[N][N]; LL res; int main() { sca 阅读全文

posted @ 2023-04-03 22:02 lyc2002 阅读(12) 评论(0) 推荐(0) 编辑

摘要:能解决什么问题 一般是给出 n 个递减的等差数列,要求对于所有等差数列中前 m 个大的数的和 时间复杂度 O(m * logn) [acwing]1262. 鱼塘钓鱼 #include <cstdio> #include <cstring> #include <algorithm> #include 阅读全文

posted @ 2023-04-01 17:19 lyc2002 阅读(17) 评论(0) 推荐(0) 编辑

摘要:快速得到一个数字的位数 int len = to_string(num).size(); 有限制的选择问题就是背包问题 无向边才可用并查集来做,有向边不行 阅读全文

posted @ 2023-03-12 18:13 lyc2002 阅读(24) 评论(0) 推荐(0) 编辑

摘要:![](https://img2023.cnblogs.com/blog/2715571/202303/2715571-20230307205256604-546504558.png) 阅读全文

posted @ 2023-03-07 20:53 lyc2002 阅读(190) 评论(0) 推荐(0) 编辑

摘要:#include <cstdio> #include <cstring> #include <stack> #include <unordered_map> using namespace std; const int N = 100010; char str[N]; stack<int> num; 阅读全文

posted @ 2023-02-25 22:19 lyc2002 阅读(20) 评论(0) 推荐(0) 编辑

摘要:代码 求区间交集 void get_intersection(vector<PII> &segs) { vector<PII> res; sort(segs.begin(), segs.end()); int l = -2e9, r = 2e9; for (auto seg : segs) { if 阅读全文

posted @ 2023-02-19 16:21 lyc2002 阅读(36) 评论(0) 推荐(0) 编辑

摘要:能解决什么问题 快速的区间操作 算法思想 给定 a[1], a[2], ..., a[n],构造差分数组 b[1], b[2], ..., b[n],使得 a[i] = b[1] + b[2] + ... + b[i]。此时,如果将 a 数组 [l, r] 区间同时加上 c,等价于 b[l] += 阅读全文

posted @ 2023-02-14 21:04 lyc2002 阅读(21) 评论(0) 推荐(0) 编辑

摘要:能解决什么问题 动态求连续区间和 对于数组 a[N] 可以求出在 a[i] 左边大于 a[i] 的数的个数,在 a[i] 右边小于 a[i] 的值 时间复杂度 O(log n) 代码 int tr[N]; int lowbit(int x) { return x & -x; } void add(i 阅读全文

posted @ 2023-02-14 20:15 lyc2002 阅读(11) 评论(0) 推荐(0) 编辑