
树状数组
树状数组
QingQingDE23
这个作者很懒,什么都没留下…
展开
-
AcWing 244. 谜一样的牛 (树状数组+二分 | 树状数组的应用)
树状数组+二分,注意题中所引导出的怎么把普通问题转化为树状数组的问题。原创 2022-09-10 12:11:37 · 150 阅读 · 0 评论 -
AcWing 243. 一个简单的整数问题2 (树状数组 区间加减|区间求和 模板)
树状数组,利用矩阵和的思想进行区间加减和区间求和。原创 2022-09-10 10:51:32 · 164 阅读 · 0 评论 -
AcWing 242. 一个简单的整数问题 (树状数组 区间加减|求单点和 模板)
树状数组模板题,利用差分对区间进行加减操作,最后求单点和。原创 2022-09-10 09:24:15 · 142 阅读 · 0 评论 -
AcWing 241. 楼兰图腾 (树状数组 单点加|求区间和 模板)
【代码】AcWing 241. 楼兰图腾 (树状数组 模板)原创 2022-09-09 22:50:54 · 167 阅读 · 0 评论 -
AcWing 1215 小朋友排队 题解(蓝桥杯 树状数组)
原题 冒泡排序+逆序对,想出考虑计算高于/低于每个身高的人数,利用树状数组进行人数修改 #include<bits/stdc++.h> using namespace std; #define int long long const int N = 1e6 + 10; int h[N], tr[N]; int n; int sum[N]; int ans; int lowbit(int x){ return x & -x; } void add(int a, int v)原创 2022-03-28 18:24:15 · 212 阅读 · 0 评论 -
AcWing 1265 数星星 题解(蓝桥杯 树状数组)
线段树的运用 原题 #include<bits/stdc++.h> using namespace std; const int N = 32010;//x、y坐标的最大值 int a[N], tr[N]; int level[N]; int n; int lowbit(int x){ return x & -x; } void add(int a){//从横坐标a开始,右边的所有树状数组的数据都应+1 for(int i = a; i <= N; i += lo原创 2022-03-25 15:59:23 · 222 阅读 · 0 评论 -
AcWing 1264 动态求连续区间和 题解(树状数组 蓝桥杯)
树状数组最基础的写法,好好记住 原题 #include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int a[N], tr[N]; int n, m; int lowbit(int x){ return x & -x; } void add(int x, int v){ for(int i = x; i <= n; i += lowbit(i)){ tr[i] += v; } }原创 2022-03-25 11:29:55 · 114 阅读 · 0 评论 -
树状数组 模板
①注意c数组需要初始化为0; ②输入数据时利用函数,而不是直接向数组输入数据 #include #include #include #include #include #include using namespace std; const int N = 50010; int c[N], n, T; int lowbit(int x){ return x&(-x); } void update(int x, int y, int n){ for(int i = x; i <= n; i +=原创 2021-08-06 09:45:44 · 57 阅读 · 0 评论