线段树
文章平均质量分 72
云淡风轻jzl
一路脚踏实地,不忘仰望星空。
展开
-
Codeforces-Contest19-D.Points-线段树+set
题目描述:Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coordinate system on it as follows: point (0, 0) is located in the bottom-left corner, Ox axis is directed right, Oy axis is directed up. Pete gives Bob原创 2021-04-09 16:53:00 · 177 阅读 · 0 评论 -
东北四省赛H-Skyscraper-线段树的区间合并优化
题目描述:At the main street of Byteland, there will be built n skyscrapers, standing sequentially one next to other. If look leftside right, sequence of their height will be a1,a2,…,an.Initially the street is empty, every skyscraper’s height is 0. Hamster is原创 2021-01-29 16:26:15 · 307 阅读 · 1 评论 -
牛客3005C-子段乘积-线段树
链接:https://ac.nowcoder.com/acm/contest/3005/C来源:牛客网题目描述:给出一个长度为 n 的数列 a1,a2,…,an,求其长度为 k 的连续子段的乘积对 998244353 取模余数的最大值。输入描述:第一行两个整数n,k。第二行n个整数,a1,a2,…,an。输出描述:输出一个整数,代表最大余数。输入样例:5 31 2 3 0 ...原创 2020-02-11 18:47:48 · 263 阅读 · 0 评论 -
牛客3566D- 小翔和泰拉瑞亚-线段树
题目描述:链接:https://ac.nowcoder.com/acm/contest/3566/D来源:牛客网小翔爱玩泰拉瑞亚 。一天,他碰到了一幅地图。这幅地图可以分为n列,第i列的高度为Hi,他认为这个地图不好看,决定对它进行改造。小翔又学会了m个魔法,实施第i个魔法可以使地图的第Li列到第Ri列每一列的高度减少Wi,每个魔法只能实施一次,魔法的区间可能相交或包含。小翔认为,一幅...原创 2019-12-27 22:13:33 · 276 阅读 · 0 评论 -
洛谷1975-[国家集训队]排队-树套树
题目描述:排排坐,吃果果,生果甜嗦嗦,大家笑呵呵。你一个,我一个,大的分给你,小的留给我,吃完果果唱支歌,大家乐和和。红星幼儿园的小朋友们排起了长长地队伍,准备吃果果。不过因为小朋友们的身高有所区别,排成的队伍高低错乱,极不美观。设第i个小朋友的身高为hi,我们定义一个序列的杂乱程度为:满足i<j且hi>hj的(i,j)数量。幼儿园阿姨每次会选出两个小朋友,交换他们的位置,请你帮...原创 2019-10-19 13:04:53 · 204 阅读 · 0 评论 -
POJ 2828-Buy Tickets-线段树区间和+逆序遍历
DescriptionRailway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue…The Lunar New Year was approaching, but unluckily the Little Cat st...原创 2019-08-25 19:53:28 · 203 阅读 · 0 评论 -
HDU 6695-Welcome Party-线段树+set二分
DescriptionThe annual welcome party of the Department of Computer Science and Technology is coming soon! Many students have been applying to show up at the welcome party, and every one of them can ch...原创 2019-08-21 20:28:59 · 357 阅读 · 0 评论 -
洛谷 P2633-Count on a tree-主席树+最近公共祖先LCA
题目描述:给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权。其中lastans是上一个询问的答案,初始为0,即第一个询问的u是明文。输入描述:第一行两个整数N,M。第二行有N个整数,其中第i个整数表示点i的权值。后面N-1行每行两个整数(x,y),表示点x到点y有一条边。最后M行每行两个整数(u,v,k...原创 2019-08-29 10:03:21 · 271 阅读 · 0 评论 -
计蒜客-XKC's basketball team-权值线段树+逆序
DescriptionXKC , the captain of the basketball team , is directing a train of nnn team members. He makes all members stand in a row , and numbers them 1⋯n from left to right.The ability of the iii-t...原创 2019-09-08 11:59:52 · 339 阅读 · 0 评论 -
洛谷1198-最大数-线段树
题目描述:现在请求你维护一个数列,要求提供以下两种操作:1、 查询操作。语法:Q L功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值。限制:L不超过当前数列的长度。(L>0)2、 插入操作。语法:A n功能:将n加上t,其中t是最近一次查询操作的答案(如果还未执行过查询操作,则t=0),并将所得结果对一个固定的常数D取模,将所得答案插入到数列的末尾。限制:n是整...原创 2019-10-05 17:57:47 · 208 阅读 · 0 评论 -
洛谷2023-维护序列-线段树-两个lazy的相互作用
题目描述:老师交给小可可一个维护数列的任务,现在小可可希望你来帮他完成。 有长为N的数列,不妨设为a1,a2,…,aN 。有如下三种操作形式:(1)把数列中的一段数全部乘一个值;(2)把数列中的一段数全部加一个值;(3)询问数列中的一段数的和,由于答案可能很大,你只需输出这个数模P的值。输入描述:第一行两个整数N和P(1≤P≤1000000000)。第二行含有N个非负整数,从左到右依...原创 2019-10-06 19:36:13 · 255 阅读 · 0 评论 -
洛谷3380-动态开点的线段树套树状数组(树套树)-模板
题目描述:您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:1.查询k在区间内的排名2.查询区间内排名为k的值3.修改某一位值上的数值4.查询k在区间内的前驱(前驱定义为严格小于x,且最大的数,若不存在输出-2147483647)5.查询k在区间内的后继(后继定义为严格大于x,且最小的数,若不存在输出2147483647)#注意上面两条要求和tyvj或...原创 2019-10-09 20:47:52 · 457 阅读 · 1 评论 -
CF 343D-Water Tree-dfs序+线段树区间和
DescriptionMad scientist Mike has constructed a rooted tree, which consists of n vertices. Each vertex is a reservoir which can be either empty or filled with water.The vertices of the tree are numb...原创 2019-08-25 11:18:32 · 189 阅读 · 0 评论 -
CF 877E-dfs序模板-Danil and a Part-time Job
DescriptionDanil decided to earn some money, so he had found a part-time job. The interview have went well, so now he is a light switcher.Danil works in a rooted tree (undirected connected acyclic g...原创 2019-08-25 09:57:46 · 298 阅读 · 0 评论 -
HDU 1025-最长上升子序列-Constructing Roads In JGShining's Kingdom
JGShining’s kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines.Half of these cities are rich in resource (we call them rich cities) while the other...原创 2019-07-24 15:28:11 · 131 阅读 · 0 评论 -
HDU 1160-FatMouse's Speed-最长下降子序列-两种求法
FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence...原创 2019-07-26 11:27:40 · 143 阅读 · 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 t...原创 2019-08-04 17:32:53 · 250 阅读 · 0 评论 -
POJ 2528-Mayor's posters-线段树+离散化
DescriptionThe 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 h...原创 2019-08-04 17:42:14 · 158 阅读 · 0 评论 -
HDU 3333-Turing Tree-线段树+离散+离线
DescriptionAfter inventing Turing Tree, 3xian always felt boring when solving problems about intervals, because Turing Tree could easily have the solution. As well, wily 3xian made lots of new proble...原创 2019-08-04 17:53:05 · 177 阅读 · 0 评论 -
HDU 4417-Super Mario-线段树+离线
DescriptionMario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory. Now the poor princess is in trouble again and Mario needs to save his lover. We regard...原创 2019-08-04 18:01:12 · 173 阅读 · 0 评论 -
CF 540E-Infinite Inversions-区间离散+线段树
(传送门)DescriptionThere is an infinite sequence consisting of all positive integers in the increasing order: p = {1, 2, 3, …}. We performed n swap operations with this sequence. A swap(a, b) is an ope...原创 2019-08-07 15:32:40 · 178 阅读 · 0 评论 -
HDU 4027-线段树+区间活性-Can you answer these queries?
(传送门)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 mar...原创 2019-08-07 16:11:33 · 140 阅读 · 0 评论 -
POJ 2104-K-th Number-主席树模板
DescriptionYou are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to...原创 2019-08-24 21:07:01 · 178 阅读 · 0 评论 -
SPOJ GSS3-区间最大连续子段和-Can you answer these queries III
DescriptionYou are given a sequence A of N (N <= 50000) integers between -10000 and 10000. On this sequence you have to apply M (M <= 50000) operations:modify the i-th element in the sequence ...原创 2019-08-25 08:59:06 · 208 阅读 · 0 评论 -
HDU 1255-覆盖的面积-线段树的扫描线算法
题目描述:给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积.输入描述:输入数据的第一行是一个正整数T(1<=T<=100),代表测试数据的数量.每个测试数据的第一行是一个正整数N(1<=N<=1000),代表矩形的数量,然后是N行数据,每一行包含四个浮点数,代表平面上的一个矩形的左上角坐标和右下角坐标,矩形的上下边和X轴平行,左右边和Y轴平行.坐标的范围...原创 2019-08-25 09:33:10 · 281 阅读 · 0 评论 -
HDU 1556-差分数组和线段树的对比分析-Color the ball
差分数组 数据结构详解戳这里!线段树 数据结构详解戳这里!这两个数据结构的操作主要有两个:更新和查询。假设数据结构总长度为n。差分数组:更新时间复杂度 O(1)查询时间复杂度 O(n)线段树 :更新时间复杂度 O(logn)查询时间复杂度 O(logn)因此,差分数组适用于多次更新,常量次查询,数据范围在1e7以内的情况;线段树适用于多次更新,多次查询,数据范围在1e5以内的...原创 2019-05-19 11:35:38 · 586 阅读 · 0 评论