
树状数组
vsooda
这个作者很懒,什么都没留下…
展开
-
PKU 3067 Japan 树状数组
求道路的交叉点数。将道路按左边城市从大到小排序。如果相同则按右边从大到小排序。这样就跟stars和cows一样了。#include #include using namespace std;const int maxn = 1010;int c[maxn],result[maxn];typedef struct{ int e, s;} node;node nd[原创 2013-01-14 09:21:30 · 607 阅读 · 0 评论 -
PKU 1195 二维树状数组
题目大意:给定n*n矩阵,和几种在线操作,包括对某一点(x,y)值修改,查询一个矩形(l, b, r, t)的元素和。二维的树状数组,直接把Update()和Getsum()改为二维即可#include using namespace std;const int maxn = 1100;int tree[maxn][maxn];int Lowbit(int x) { re原创 2013-01-12 22:44:59 · 667 阅读 · 0 评论 -
PKU 2481 COWS 排序 + 树状数组
排好序后就跟stars那题一样了一次遍历排序后的数组,由于比当前遍历元素strong的区间只可能存在于已经遍历过的元素中;所以我们可以放心大胆的直接对树状数组求和然后向后更新树状数组中统治x的点上的值,因为那些位置都多了一个比 以他们为左端点的区间 强壮 的区间;#include #include using namespace std;const int maxn =原创 2013-01-13 11:00:18 · 596 阅读 · 0 评论 -
PKU 2352 Stars 求比较小的数字个数
题目意思就是求每个星星左下方的星星的个数,由于y轴已经排序好了,我们可以直接用按x轴建立一维树状数组,然后求相当于它前面比它小的个数,模板直接一套就搞定了~~#include using namespace std;const int MAX = 32000 + 10;int c[MAX], level[MAX];int Lowbit(int x) { return原创 2013-01-11 21:37:19 · 720 阅读 · 0 评论 -
PKU 2299 求解逆序数(使用归并或者树状数组) 树状数组及入门知识
归并ac代码为:#include #include using namespace std;#define MAX 500005int a[MAX], t[MAX];__int64 cnt;void Merge(int l, int mid, int r){ int i = l, j = mid + 1, k = 0; while(i <= mid && j <= r原创 2013-01-11 15:41:03 · 711 阅读 · 0 评论