![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
树状数组
h_lizeming
这个作者很懒,什么都没留下…
展开
-
树状数组 理解入门
int lowbit(int t) { return t&(-t); }void add(int x,int y) { for(int i=x;i<=n;i+=lowbit(i)) tree[i]+=y; }int getsum(int x) { int ans=0; for(int i=x;i>0;i-=lowbit(i)) ans+=tree[i]...原创 2018-08-12 09:54:41 · 183 阅读 · 0 评论 -
L - Find the nondecreasing subsequences HDU - 2227 (离散化树状数组)
How 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 subsequences , {1}, {2}, {...原创 2018-08-13 15:06:54 · 218 阅读 · 0 评论 -
Cow Sorting HDU - 2838
题意:就是求将之前的排列变成一个递增的排列,每交换两个数的代价为两个数的和,求变成递增的排列所需的最小代价为多少。本题相当于冒泡排序,对于冒泡排序,每个点的贡献价值的次数等于前面大于它的数的个数加上后面小于它的个数。分析:其实这个结果和逆序数有关,对某个位置i,如果前面比他大的有x个,那么a[i]至少要加x次 如果后面有y个比a[i]小,那么a[i]至少要加y次,也就是说用两个树状数组来...原创 2018-08-12 14:04:36 · 176 阅读 · 0 评论 -
H - Rotate HDU - 2688(树状数组水题)
Recently yifenfei face such a problem that give you millions of positive integers,tell how many pairs i and j that satisfy F[i] smaller than F[j] strictly when i is smaller than j strictly. i and j is...原创 2018-08-12 11:17:53 · 205 阅读 · 0 评论 -
F - Cube HDU - 3584 (三维树状数组)
Given an N*N*N cube A, whose elements are either 0 or 1. A[i, j, k] means the number in the i-th row , j-th column and k-th layer. Initially we have A[i, j, k] = 0 (1 <= i, j, k <= N). We defin...原创 2018-08-12 11:02:49 · 145 阅读 · 0 评论 -
Ping pong HDU - 2492(一维树状数组 从前扫再从后扫)
N(3<=N<=20000) ping pong players live along a west-east street(consider the street as a line segment). Each player has a unique skill rank. To improve their skill rank, they often compete with ...原创 2018-08-12 11:01:32 · 212 阅读 · 0 评论 -
Stars
Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and ...原创 2018-08-12 10:48:27 · 558 阅读 · 0 评论 -
C - 敌兵布阵 HDU - 1166(树状数组)
C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。 中央情报局要研究敌人究竟演习什么战术,所...原创 2018-08-12 10:46:30 · 341 阅读 · 0 评论 -
B - KiKi's K-Number HDU - 2852 (树状数组套二分)
For the k-th number, we all should be very familiar with it. Of course,to kiki it is also simple. Now Kiki meets a very similar problem, kiki wants to design a container, the container is to support t...原创 2018-08-12 10:33:44 · 209 阅读 · 0 评论 -
A - See you~ HDU - 1892 (二维树状数组入门题目)
Now I am leaving hust acm. In the past two and half years, I learned so many knowledge about Algorithm and Programming, and I met so many good friends. I want to say sorry to Mr, Yin, I must leave now...原创 2018-08-12 10:19:40 · 300 阅读 · 0 评论 -
N - Stars HDU - 2642 (二维树状数组 )
Yifenfei is a romantic guy and he likes to count the stars in the sky. To make the problem easier,we considerate the sky is a two-dimension plane.Sometimes the star will be bright and sometimes the s...原创 2018-08-14 09:05:02 · 155 阅读 · 0 评论