数据结构——线段树
邵光亮
要为自己喜欢的事情不留余力
展开
-
poj2823 Sliding Window(单调队列)
题意:给定一个长度为 NNN 的数字序列,要求你求出每个长度为 KKK 的区间内的最小值与最大值。单调队列做法:const int N = 1e6 + 10;const int mod = 998244353;int a[N], maxx[N], minn[N], queue1[N], queue2[N];//queue存位置int i, n, k, front1, front2, tail1, tail2, cnt;int main(){ sdd(n, k); cn..原创 2020-10-07 20:49:17 · 140775 阅读 · 0 评论 -
LOJ6285 数列分块入门9(分块毒瘤)
题目描述:给出一个长为 的数列,以及 个操作,操作涉及询问区间的最小众数。输入格式第一行输入一个数字 。第二行输入 个数字,第 个数字为 ,以空格隔开。接下来输入 行询问,每行输入两个数字 、,以空格隔开。表示查询位于 的数字的众数。输出格式对于每次询问,输出一行一个数字表示答案。样例样例输入41 2 2 41 21 42 43 4样例输出122...原创 2020-03-27 17:12:11 · 142121 阅读 · 0 评论 -
Codeforces 1321 E. World of Darkraft: Battle for Azathoth(线段树)
题意:有 nnn 个武器每个武器 aia_iai 攻击买这个花费 caic_{a_i}cai,mmm 个防具每个防御 bib_ibi 花费 cbic_{b_i}cbi,ppp 个怪物每个 xxx 攻击 yyy 防御掉 zzz 金币,武器任选一个防具任选一个,把能杀的怪物都杀掉,能杀的怪物是你的攻击大于它的防御 你的防御大于它的攻击,问杀怪收益-买装备花费最多为多少把武器的初始收益...原创 2020-03-02 15:47:56 · 138557 阅读 · 0 评论 -
2020 CCPC Wannafly Winter Camp Day1 I K小数查询(线段树套权值线段树)
题意:给定一个长度为 nnn 的序列 AAA 和 mmm 次操作。操作分两种:(1,l,r,x)(1≤l≤r≤n, 1≤x≤109)(1,l,r,x) \left(1\leq l\leq r\leq n,\ 1\leq x\leq10^9\right)(1,l,r,x)(1≤l≤r≤n, 1≤x≤109) ,表示对 ∀i∈[l,r]令Ai=min(Ai,x)\fo...原创 2020-02-21 18:37:06 · 180 阅读 · 0 评论 -
CodeForces 1263E Editor(线段树)
Description:\quadThe development of a text editor is a hard problem. You need to implement an extra module for brackets coloring in text.\quadYour editor consists of a line with infinite length and ...原创 2019-11-30 22:27:07 · 403 阅读 · 0 评论 -
2019ICPC银川 Pot (线段树)
\quad这道题就是1−n1-n1−n个数mmm个操作,其中一个就是让区间的数都乘上2−102-102−10中的一个数,然后求区间的任意一个满足可以被pmp^{m}pm整除,不能被pm+1p^{m+1}pm+1整除,ppp是一个质数,求最大的mmm。\quad因为只有乘2−102-102−10,2−102-102−10直接的质数只有2,3,5,72,3,5,72,3,5,7,要保证m最大我...原创 2019-11-30 17:19:33 · 401 阅读 · 0 评论 -
2019ICPC南昌邀请赛J题 Distance on the tree(主席树)
Descriptions:\quadDSM(Data Structure Master) once learned about tree when he was preparing for NOIP(National Olympiad in Informatics in Provinces) in Senior High School. So when in Data Structure Cla...原创 2019-11-29 20:12:36 · 389 阅读 · 0 评论 -
HDU 4471 Super Mario(主席树)
Problem Description\quadMario 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 lov...原创 2019-11-29 16:53:06 · 212 阅读 · 0 评论 -
CodeForces 1277D Optimal Subsequences(主席树or贪心+线段树)
Description\quadYou are given a sequence of integers a=[a1,a2...an]a=[a_{1},a_{2}...a_{n}]a=[a1,a2...an] of length nnn. Its subsequence is obtained by removing zero or more elements from the seque...原创 2019-11-26 11:15:00 · 233 阅读 · 0 评论 -
主席树
主席树主要解决的问题就是区间第K小数的问题。主席树为什么叫主席树呢?因为发明它的folite被我们叫做folite主席,所以就叫主席树。主席树也叫做可持久化线段树,因为其中的每一颗树都是一颗权值线段树,可持久化就是他可以保存的历史版本,因为线段树每次修改只会修改一个点或者一条链的信息。当确定了元素个数n,或者key的范围[1,U],建出的线段树形态是唯一的。对两棵key的上界相同的线段树进...原创 2019-11-25 22:24:01 · 1494 阅读 · 0 评论 -
HDU 1540 Tunnel Warfare(线段树)
Description:During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally speaking, villages connected by tunnels lay in a...原创 2019-11-02 17:59:26 · 179 阅读 · 0 评论 -
HDU 6315 Naive Operations(线段树)
Description:In a galaxy far, far away, there are two integer sequence a and b of length n.b is a static permutation of 1 to n. Initially a is filled with zeroes.There are two kind of operations:...原创 2019-10-30 17:45:26 · 235 阅读 · 0 评论 -
POJ 1436 Horizontally VisibleSegments(线段树成段更新+区间覆盖染色)
DescriptionThere is a number of disjoint vertical line segments in the plane. We say that two segments are horizontally visible if they can be connected by a horizontal line segment that does not h...原创 2019-08-29 09:56:50 · 540 阅读 · 0 评论 -
HDU 1542 Atlantis(线段树:扫描线)
Problem Description There 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 unfortunat...原创 2019-08-29 11:24:02 · 629 阅读 · 0 评论 -
HDU-1754-I Hate It(线段树+区间最大值)
Description:很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。这让很多学生很反感。不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。Input本题目包含多组测试,请处理到文件结束。在每个测试的第一行,有两个正整数 N 和 M ( 0<N<=20000...原创 2019-06-03 21:07:10 · 640 阅读 · 0 评论 -
HDU4027 Can you answer these queries? (线段树)
Description:A 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 marked...原创 2019-09-19 17:47:56 · 466 阅读 · 0 评论 -
POJ - 2528 Mayor's posters (离散化+线段树区间覆盖)
Description: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 counci...原创 2019-09-25 09:05:26 · 285 阅读 · 0 评论 -
POJ 3264 Balanced Lineup (RMQ求区间最值)
DescriptionFor the daily milking, Farmer John'sNcows (1 ≤N≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. T...原创 2019-09-28 16:33:44 · 231 阅读 · 0 评论 -
HDU - 1540 Tunnel Warfare (线段树维护区间最大连续值)
Description:During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally speaking, villages connected by tunnels lay in a...原创 2019-09-29 17:09:28 · 220 阅读 · 0 评论 -
UVA11297 Census(二维线段树)
DescriptionThis year, there have been many problems with population calculations, since in some cities, there are many emigrants, or the population growth is very high. Every year the ACM (for Ass...原创 2019-10-07 17:33:52 · 195 阅读 · 0 评论 -
POJ 2886(线段树+单点修改+约瑟夫环)
DescriptionNchildren are sitting in a circle to play a game.The children are numbered from 1 toNin clockwise order. Each of them has a card with a non-zero integer on it in his/her hand. The g...原创 2019-08-28 20:18:30 · 722 阅读 · 0 评论