
树状数组
wtcl
这个作者很懒,什么都没留下…
展开
-
ZYB s Premutation HDU 5592(树状数组+二分)
题意:给定数组每个数前面(包括这个数)的逆序对数量,求原数组的值 思路: 1.a[i]-a[i-1]可以得到该数的之前比它大的数的数量 2.从后往前遍历,只需要求出数组的第(a[i]-a[i-1]+1)大的数就是该位的值, 代码: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int N=5e4+10; i原创 2020-06-29 12:22:58 · 139 阅读 · 0 评论 -
Level Up HDU - 5788(主席树+树状数组+dfs序)
题目:https://vjudge.net/problem/HDU-5788 题意:给定一颗树,每个点都有权值(1是根节点)mid[i]是以i为根节点的子树的所有节点的权值的中位数。选择一个节点使其权值变为100000(树上节点的权值都不大于100000)使得mid[i]之和最大,输出最大的和。 思路: 1.如果选择某一个节点,只会影响它本身还有祖先节点的mid值,而且只有在该节点的权值小于等于祖先节点的权值是才会将祖先节点的中位数变成中位数的下一位。求出每个节点的curmid和nextmid(中位数和中位原创 2020-06-24 22:45:17 · 146 阅读 · 0 评论 -
树状数组总结
树状数组是一种可以动态维护前缀和的算法 树状数组可以完成的操作线段树都可以完成 树状数组相较线段树优点在于 1.代码简单 不易出错 2.所占空间小(有些题目对内存的要求比较高 用线段树会超内存) 比如:https://editor.youkuaiyun.com/md/?articleId=106205428 代码: 树状数组的应用 1. ...原创 2020-05-19 01:12:51 · 123 阅读 · 0 评论 -
一个简单的整数问题(树状数组+差分)
题目链接:https://www.acwing.com/problem/content/248/ 树状数组+差分可以实现区间修改和单点查询 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int N=1e5+10; #define ll long long ll a[N]; ll c[N];int n,m;原创 2020-05-19 01:06:36 · 173 阅读 · 0 评论 -
楼兰图腾(树状数组 逆序对)
题目链接:https://www.acwing.com/problem/content/243/ 树状数组可以直接求前边比他小的数和后边比他小的数 通过总的数减去比他小的数可以得到比他大的数 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int N=2e5+10; int c[N],a[N];int n;原创 2020-05-19 00:52:15 · 179 阅读 · 0 评论 -
Educational Codeforces Round 87 (Rated for Div. 2)D. Multiset(树状数组)
题目链接:https://codeforces.ml/contest/1354/problem/D 思路:树状数组+二分 树状数组其实就是动态维护前缀和的一种数据结构 代码: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int N=1e6+10; int s[N]; int c[N]; int n,q;原创 2020-05-19 00:38:01 · 161 阅读 · 0 评论