数据结构 线段树
文章平均质量分 85
obsorb_knowledge
心有不甘,呼唤着我
展开
-
约瑟夫问题
题目:有一桌人(共N个人)在做一个游戏,其中一个人从1开始报数,报到第M个数的人从桌上离开,然后继续从下一个人开始从1报数,然后直到桌上的人数小于M,游戏终止请在最短的时间内实现这个过程(如果给每个人编个固定号码的话,要求输出最后剩下的人员编号),写明对应时间复杂度首先看到这道题,我想大家应该和我一样,都会想到暴力,去解。可想而知暴力的时间复杂度为O(n-m+1)*m极端情况,复杂度较高。这里我想到用线段树进行优化。记录当前数到m时,前面(包括本身,已经离开桌子的不算)还有多少人,记录为.原创 2021-08-05 11:38:05 · 277 阅读 · 0 评论 -
406. 根据身高重建队列(贪心+简洁代码的线段树优化)
题目描述:假设有打乱顺序的一群人站成一个队列,数组 people 表示队列中一些人的属性(不一定按顺序)。每个 people[i] = [hi, ki] 表示第 i 个人的身高为 hi ,前面 正好 有 ki 个身高大于或等于 hi 的人。请你重新构造并返回输入数组people 所表示的队列。返回的队列应该格式化为数组 queue ,其中 queue[j] = [hj, kj] 是队列中第 j 个人的属性(queue[0] 是排在队列前面的人)。示例 1:输入:people = [[7,0.原创 2021-02-22 20:22:14 · 466 阅读 · 0 评论 -
Mayor's posters (线段树+离散化+加思维)
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finall...原创 2018-05-30 20:05:11 · 3935 阅读 · 8 评论 -
2018年湘潭大学程序设计竞赛 H 统计颜色( 区间更新线段树 + 状态压缩 )
n个桶按顺序排列,我们用1~n给桶标号。有两种操作:1 l r c 区间[l,r]中的每个桶中都放入一个颜色为c的球 (1≤l,r ≤n,l≤r,0≤c≤60)2 l r 查询区间[l,r]的桶中有多少种不同颜色的球 (1≤l,r ≤n,l≤r)输入描述:有多组数据,对于每组数据:第一行有两个整数n,m(1≤n,m≤100000)接下来m行,代表m个操作,格式如题目所示。输出描述:...原创 2018-04-27 17:11:04 · 200 阅读 · 0 评论 -
Master of GCD HDU - 6273 (区间更新,线段树)
Hakase has n numbers in a line. At first, they are all equal to 1. Besides, Hakase is interested inprimes. She will choose a continuous subsequence [l, r] and a prime parameter x each time and forever...原创 2018-04-23 21:47:21 · 1208 阅读 · 0 评论 -
Ultra-QuickSort POJ - 2299 (数状数组 线段树 归并排序 求逆序数)
In 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 sequence is sorted i...原创 2018-04-10 09:19:48 · 223 阅读 · 0 评论 -
线段树
线段树1 建树 以求区间最大值为例a数组为构造线段树的数组root 为线段树的树根star 为数组起始下表end 为数组终点下表开始 root = 1,star = 1,end = n; void build(int root,int star,int end) { if(star==end) { int k; scanf("%d",&a...原创 2017-10-14 16:18:55 · 294 阅读 · 0 评论 -
HDU - 1698 D - Just a Hook (线段树区间更新)
In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length. No原创 2017-10-14 17:23:35 · 308 阅读 · 0 评论 -
hdu 1166 简单线段树
C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。 中央情报局要研究敌人究竟演习什么战术,原创 2017-09-29 11:04:56 · 159 阅读 · 0 评论 -
CodeForces - 602B Approximating a Constant Range 【线段树 + 尺取法】
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be原创 2017-10-27 13:08:12 · 306 阅读 · 0 评论