![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
———线段树|树状数组
文章平均质量分 88
MissZhou要努力
不晓日月,不辩兰艾,终日碌碌,安与燕雀相随乎
展开
-
POJ1151 (HDU 1542) Atlantis【矩形面积并,线段树+离散化+扫描线模板】
DescriptionThere are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of the island. But unfortunately, these map原创 2016-03-22 08:06:35 · 1512 阅读 · 0 评论 -
hdu4325 Flowers【树状数组区间更新单点求值 离散化】
Problem DescriptionAs is known to all, the blooming time and duration varies between different kinds of flowers. Now there is a garden planted full of flowers. The gardener wants to know how many fl原创 2016-03-27 16:29:23 · 1001 阅读 · 0 评论 -
poj2886Who Gets the Most Candies?【线段树单点更新】
DescriptionN children are sitting in a circle to play a game.The children are numbered from 1 to N in clockwise order. Each of them has a card with a non-zero integer on it in his/her hand. The原创 2016-03-08 20:46:42 · 482 阅读 · 0 评论 -
poj3667hotal线段树【经典】
这个题又是把懒惰标记和动作状态混在一起了==还有push-up push-down 背了吧。。。 好怕怕…… 注意1和L!#include #include#includeusing namespace std;struct node{ int l,r,lsum,rsum,sum,loop;}tree[400000];int Find_Max(int a,int原创 2015-08-10 20:35:32 · 360 阅读 · 0 评论 -
hdu1394Minimum Inversion Number逆序数
链接在这里呀在这里其实第一次看到这个题是六月1号。然而即使学长讲了一遍没懂依旧没问 好歹今天一下午终于明白了一串数字要怎么联想到线段树呢?把数字本身当作线段树中的位置--这个是这题的一个点Tip2:由于操作只有把开头的一个元素放到最后位置,故,其他数字相对位置不变啊。每次更新的数字就是从开始累加的==Tip3:n-1-2*a[i]咋来的?对于某个数a[i] 比他大的数有n-1-a[原创 2015-08-10 17:34:27 · 453 阅读 · 0 评论 -
线段树&树状数组总结篇
1、 入门题:hdu1166敌兵布阵单点更新区间求和 线段树:using namespace std;struct node{ int l,r,sum;}num[maxn*4];int m[maxn];char s[10];int t,n,a,b;void build(int root,int l,int r){ num[root].l=l;原创 2016-05-12 22:03:12 · 1815 阅读 · 0 评论 -
hdu2795Billboard【线段树】
Problem DescriptionAt the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the place where all possible announcement原创 2015-09-21 20:35:50 · 342 阅读 · 0 评论 -
hdu1698just a hook 线段树
懒惰标记的入门题==讲解详见小伙伴的博客 点击打开链接 貌似只是加了注释==我的代码->俩人改了好久才过==注意.L L .R R的区别#include #include#includeusing namespace std;struct node{ int l,r,val,tag; int mid(){return (l+r)/2;}}tree[3000原创 2015-08-08 18:48:37 · 599 阅读 · 0 评论 -
hdu1166敌兵布阵 线段树or树状数组
Problem DescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。原创 2015-05-29 16:36:38 · 527 阅读 · 0 评论 -
poj2299Ultra-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 seque原创 2016-02-01 10:16:16 · 591 阅读 · 0 评论 -
hdu4267A Simple Problem with Integers【树状数组区间更新/单点查询】
终于把区间更新搞明白了,书上的写法实在是晦涩难懂,明明是区间更新,干嘛非要生搬硬套单点更新的写法??区间更新,带入函数的参数是向下管理从1到这个点的所有区域的,而单点更新,已知了一个点,管理这个点的高层们都需要更新自己的值,这就是本质区别,而且选择适合的算法时间也要稍微快一点/*************hdu42672016.2.1483MS 29952K 1447 B G++old3原创 2016-02-01 14:22:31 · 513 阅读 · 0 评论 -
poj1195Mobile phones【二维树状数组。单点更新/区间求和】
为了检验自己二位树状数组学的怎么样才做的水题 貌无悬念的1A/************poj11952016.2.15024K 954MS G++************/#include #include#includeusing namespace std;int tree[1050][1050],n,t,x,y,a,l,b,r,cmd;int lowbit(int i原创 2016-02-01 15:12:52 · 452 阅读 · 0 评论 -
hdu 1828 Picture【扫描线求周长模板题】
上周在做ac自动机+dp这种混合的题时,就超不爽的,这周居然要做线段树+几何的题,我的内心上崩溃的o(>﹏既然不是自己做的,总还是要讲讲扫描线是个什么玩意==扫描线,顾名思义,就是用一条线捋着各个边从下到上过一遍,每遍历一个高度的边,累加长度:点击打开链接计算横线部分的方法:现在这次总区间被覆盖的长度和上一次总区间被覆盖的长度的差的绝对值:fabs(a[1].len - pre)计算竖原创 2016-03-21 21:51:57 · 584 阅读 · 0 评论 -
POJ 2155 Matrix 【二维线段树模板题】
DescriptionGiven an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row and j-th column. Initially we have A[i, j] = 0 (1 <= i, j <= N).We can change the原创 2016-03-18 10:51:07 · 649 阅读 · 0 评论 -
poj2823Sliding Window【线段树维护滚动区间最值】
DescriptionAn array of size n ≤ 10 6 is given to you. There is a sliding window of sizek which is moving from the very left of the array to the very right. You can only see thek numbers in the原创 2016-03-17 13:31:12 · 649 阅读 · 0 评论 -
poj2299Ultra-QuickSort【线段树求逆序数】离散化
Ultra-QuickSortTime Limit: 7000MS Memory Limit: 65536KTotal Submissions: 52097 Accepted: 19113DescriptionIn this problem, you have to analyze a particular sorting原创 2016-03-15 16:48:59 · 1008 阅读 · 3 评论 -
hdu4006The kth great number【线段树第k大】
The kth great numberTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 9072 Accepted Submission(s): 3592Problem DescriptionXiao Ming原创 2016-03-08 16:25:14 · 781 阅读 · 0 评论 -
hdu2852KiKi's K-Number【线段树第k小】
Total Submission(s): 3314 Accepted Submission(s): 1487Problem DescriptionFor the k-th number, we all should be very familiar with it. Of course,to kiki it is also simple. Now Kiki meets a原创 2016-03-08 10:33:36 · 508 阅读 · 0 评论 -
hdu4027Can you answer these queries?【线段树区间更新区间求和】
Problem DescriptionA lot of battleships of evil are arranged in a line before the battle. Our commander decides to use our secret weapon to eliminate the battleships. Each of the battleships can be原创 2016-03-07 21:33:26 · 634 阅读 · 0 评论 -
poj2528Mayor's posters【离散化线段树区间更新】
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 54376 Accepted: 15796DescriptionThe citizens of Bytetown, AB, could not stand that the candidates in the mayoral ele原创 2016-03-07 19:52:42 · 501 阅读 · 0 评论 -
leetcode 307. Range Sum Query - Mutable【线段树,指针】
Given an integer arraynums, find the sum of the elements between indicesiandj(i≤j), inclusive.Theupdate(i, val)function modifiesnumsby updating the element at indexitoval.Example:...原创 2019-07-21 15:53:38 · 204 阅读 · 0 评论