
数据结构——树状数组
邵光亮
要为自己喜欢的事情不留余力
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LibreOJ #144. DFS 序 1(dfs序+树状数组)
Description:这是一道模板题。给一棵有根树,这棵树由编号为 1…N 的 N 个结点组成。根结点的编号为 R。每个结点都有一个权值,结点 i 的权值为 vi。接下来有 M 组操作,操作分为两类:1 a x,表示将结点 a 的权值增加 x;2 a,表示求结点 a 的子树上所有结点的权值之和。Input第一行有三个整数 N,M 和 R。第二行有 N 个整数,第 i 个整数表示 vi。在接下来的 N−1 行中,每行两个整数,表示一条边。在接下来的 M 行中,每行一组操作。Output原创 2020-10-08 11:08:32 · 144107 阅读 · 0 评论 -
Codeforces 1354 D. Multiset(树状数组)
题意;要你实现一个求第k大数的数据结构。树状数组模板题。AC代码:const int N = 1e6 + 50;int a[N];int n, q;void add(int p, int val){ while (p <= n) { a[p] += val; p += lowbit(p); }}int query(int p){ int res = 0, cnt = 0; per(i, 20, 0) { if (res + (1 << i..原创 2020-05-20 17:05:19 · 139827 阅读 · 0 评论 -
Codeforces 1311 F. Moving Points (树状数组+离散化)
Description:There are nnn points on a coordinate axis OX. The i−thi-thi−th point is located at the integer point xixixi and has a speed vivivi. It is guaranteed that no two points occupy the same coo...原创 2020-02-25 11:55:02 · 139520 阅读 · 0 评论 -
CodeForces - 1288E Messenger Simulator(树状数组)
这道题,一开始模拟半天不对,数据量不是模拟可以写的,想到了树状数组,转化成区间求和。具体可以看这个博主的文章写的很详细:点击这里我的代码:#include <cstdio>#include <vector>#include <queue>#include <cstring>#include <cmath>#include ...原创 2020-01-15 19:53:50 · 297 阅读 · 0 评论 -
POJ 3468(树状数组+区间修改)
题目描述给定一个长度为N的数列A,以及M条指令,每条指令可能是以下两种之一:1、“C l r d”,表示把 A[l],A[l+1],…,A[r] 都加上 d。2、“Q l r”,表示询问 数列中第 l~r 个数的和。对于每个询问,输出一个整数表示答案。输入格式第一行两个整数N,M。第二行N个整数A[i]。接下来M行表示M条指令,每条指令的格式如题目描述所示。...原创 2019-08-12 21:31:43 · 744 阅读 · 0 评论 -
hdu 2227 Find the nondecreasing subsequences (离散化+树状数组+DP)
Problem DescriptionHow many nondecreasing subsequences can you find in the sequence S = {s1, s2, s3, ...., sn} ? For example, we assume that S = {1, 2, 3}, and you can find seven nondecreasing sub...原创 2019-09-28 16:56:31 · 312 阅读 · 0 评论 -
BNU 25586 Mega Inversions(树状数组求逆序数对)
Description:The n2upper bound for any sorting algorithm is easy to obtain: just take two elements that are misplaced with respect to each other and swap them. Conrad conceived an algorithm that pr...原创 2019-09-26 21:41:33 · 203 阅读 · 0 评论 -
HDU 3874 Necklace (树状数组去重+离线处理)
Problem DescriptionMery has a beautiful necklace. The necklace is made up of N magic balls. Each ball has a beautiful value. The balls with the same beautiful value look the same, so if two or more...原创 2019-09-26 20:35:57 · 359 阅读 · 0 评论 -
POJ 2299 Ultra-QuickSort(树状数组+离散化 或 归并排序求逆序)
DescriptionIn this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequen...原创 2019-08-28 16:37:37 · 622 阅读 · 0 评论 -
HDU 2838 Cow Sorting(双树状数组+求逆序数)
Problem DescriptionSherlock's N (1 ≤ N ≤ 100,000) cows are lined up to be milked in the evening. Each cow has a unique "grumpiness" level in the range 1...100,000. Since grumpy cows are more likely...原创 2019-08-28 10:46:41 · 723 阅读 · 0 评论 -
HDU 1394 Minimum Inversion Number(树状数组求逆序对)
Problem Description The inversion number of a given number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i < j and ai > aj. For a given sequence of numbers a1...原创 2019-08-28 10:22:33 · 743 阅读 · 0 评论