数据结构——树状数组
手可摘星辰!!
这个作者很懒,什么都没留下…
展开
-
POJ 3321 AppleTree
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn=100001; struct node1 { int next,tail; }edge[maxn]; struct node...原创 2019-08-06 21:18:26 · 56 阅读 · 0 评论 -
树状数组求逆序对
我们可以先开一个大小为a的最大值的数组t,每当读入一个数时,我们可以用桶排序的思想,将t[a[i]]加上1,然后我们统计t[1]~t[a[i]]的和ans,ans - 1(除掉这个数本身)就是在这个数前面有多少个数比它小。我们只要用i-ans就可以得出前面有多少数比它大,也就是逆序对的数量。 #include<iostream> #include<cstdio> #incl...原创 2019-05-30 15:02:38 · 137 阅读 · 0 评论 -
楼兰图腾 树状数组求逆序数
这个博客很详细 https://blog.csdn.net/ssimple_y/article/details/53744096 #include <cstdio> #include <cstring> #include <iostream> #define N 200001 using namespace std; int n,lh[N],ll[N],rh[...原创 2019-08-12 14:24:04 · 114 阅读 · 0 评论 -
A Tiny Problem with intergers 树状数组 区间更新 单点查询
建立树状数组时,建立的是 A【i】-A【i-1】 A【3】= A【1】-A【0】+A【2】-A【1】+A【3】-A【2】 刚好单点查询 #include<iostream> #include<cstdio> #include<cstring> int a[100010],c[200010]; int n,m; int lowbit(int x) { ...原创 2019-08-12 15:27:10 · 107 阅读 · 0 评论 -
A Simple Problem with Integers 树状数组 区间更新 区间查询
树状数组模板 https://www.cnblogs.com/xenny/p/9739600.html #include<cstdio> #include<iostream> #include<cstring> using namespace std; int n,m; long long a[500005] = {0}; long long sum1[5000...原创 2019-08-12 16:20:02 · 100 阅读 · 0 评论 -
Lost Cows 树状数组逆序数应用
规律: 要确定某个数字p,那么我们就要知道p的前面有多少个数字比它小,记为m,p的后面有多少个数字比他小,记为n,那么p的位置就该在这个数列中的第m+n+1处,我们就二分这个p,拿每次得到的mid来和m+n+1来比较大小,如果m+n+1>mid就说明mid取小了,这个时候,我们就把left = mid+1;如果m+n+1<mid,那就说明mid取大了,这个时候我们就要把mid = right...原创 2019-08-12 17:25:44 · 67 阅读 · 0 评论