树状数组之单点修改并求全局第K小

摘要: 树状数组模板如下 可实现建树、查询、倍增求第K小 class Fenw { public: int n; vector<int> c; Fenw(int size) { n = size; c.resize(n+1, 0); } void add(int i, int x) { while (i < 阅读全文
posted @ 2025-07-16 16:06 TaopiTTT 阅读(36) 评论(0) 推荐(0)

组合数模板

摘要: 暴力法 int C(int a,int b){ int res=1; for(int i=a,j=1;j<=b;i--,j++){ res=res*i/j; if(res>n) return res; } return res; } 优化 const int N=1e5+5; const int M 阅读全文
posted @ 2025-04-08 20:10 TaopiTTT 阅读(15) 评论(0) 推荐(0)

双指针优化二维前缀和

摘要: 先看例题https://www.luogu.com.cn/problem/P8783 由题意可以快速写出一个\(n^4\)复杂度的二维前缀和,如下 for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ for(int x=i;x<=n;x++){ for(int 阅读全文
posted @ 2025-02-19 19:52 TaopiTTT 阅读(43) 评论(0) 推荐(0)

质因数分解+状态压缩求完全平方数

摘要: 例题https://www.luogu.com.cn/problem/P10724 小性质:完全平方数的质因子出现数量应该为偶数,因此可以用异或去判断是否为偶数 前缀异或和性质: 因为:\(a xor a=0\),而且异或满足交换律。 所以当前的前缀异或\(sxor\)之前出现过,说明中间的那些\( 阅读全文
posted @ 2024-11-26 19:23 TaopiTTT 阅读(47) 评论(0) 推荐(0)

形如求某一数字的倍数的方案数的题

摘要: 例题:https://ac.nowcoder.com/acm/contest/95928/D 题意简析:在数组中选取两个数 \(a_i ,a_j\),使得两数乘积为495的倍数,同时可以进行一次(仅一次)的操作:使某个\(a_i\)加1,求出最大方案数 思路:通常遇到这种题目,需要对目标数进行质因数 阅读全文
posted @ 2024-11-25 22:00 TaopiTTT 阅读(19) 评论(0) 推荐(0)

维护带权并查集

摘要: 大概叫这个名字吧 https://atcoder.jp/contests/abc380/tasks/abc380_e #include<bits/stdc++.h> #define endl '\n' #define lowbit(x) (x&-x) using namespace std; typ 阅读全文
posted @ 2024-11-25 21:34 TaopiTTT 阅读(13) 评论(0) 推荐(0)

动态规划优化技巧

摘要: 浅谈动态规划基础优化 原题:https://www.luogu.com.cn/problem/P1776 这题虽然标绿,但是数据极水,通过解绑优化即可卡着1s时限通过 未优化代码: const int N=1e5+5; int v[N],w[N],m[N]; int dp[N]; void solv 阅读全文
posted @ 2024-11-14 20:50 TaopiTTT 阅读(47) 评论(0) 推荐(0)

拆环成链+贪心区间覆盖+倍增

摘要: 好题,先插个眼,以后水平上来了再看 https://www.luogu.com.cn/problem/P4155 #include<bits/stdc++.h> #define endl '\n' #define lowbit(x) (x&-x) using namespace std; typed 阅读全文
posted @ 2024-11-12 20:22 TaopiTTT 阅读(27) 评论(0) 推荐(0)

链式并查集合并(裸板)

摘要: 对于操作:将一段元素合并为同类。 在合并 \([l,r]\) 这一段数的时候,其实有很多数本来就在一个并查集里。我们只需要合并若干个还没有合并的并查集,而不需要从 \(l\) 到 \(r\) 一个一个合并。因为只要合并了这几个并查集,效果等价于把 \([l,r]\) 直接合并了。 实现方法:每次记录 阅读全文
posted @ 2024-11-06 18:51 TaopiTTT 阅读(64) 评论(0) 推荐(0)

链式并查集合并+维护区间和

摘要: 用于解决区间合并查询问题 https://ac.nowcoder.com/acm/contest/93847/E #include<bits/stdc++.h> #define endl '\n' #define int long long #define lowbit(x) (x&-x) usin 阅读全文
posted @ 2024-11-04 20:15 TaopiTTT 阅读(15) 评论(0) 推荐(0)