
线段树
csu_xiji
这个作者很懒,什么都没留下…
展开
-
HDU 4391 Paint The Wall 线段树染色问题
题目大意:给出nnn面墙的初始颜色,mmm个询问(a,l,r,z)(a,l,r,z)(a,l,r,z),如果a=1a=1a=1,表示把[l,r][l,r][l,r]的所有墙染成zzz,如果a=2a=2a=2,表示查询[l,r][l,r][l,r]的颜色为zzz的墙的数量。思路:线段树比分块哈希快得多……就离谱。修改操作就不多说了,一个lazylazylazy标记就行了,主要是查询,暴力找肯定不行...原创 2020-04-07 14:34:44 · 198 阅读 · 0 评论 -
Round H 2019 - Kick Start 2019 H-index 线段树
https://codingcompetitions.withgoogle.com/kickstart/round/0000000000050edd/00000000001a274e题目大意:ttt组数据,每组给一个数组aaa,对于每个iii,输出最大的ansians_iansi,使得a[1……i]a[1……i]a[1……i]中至少有ansians_iansi个数>=ansi>=...原创 2020-03-21 21:44:53 · 217 阅读 · 0 评论 -
codeforces gym 100803G Flipping Parentheses 线段树
https://vjudge.net/contest/285175#problem/J题目大意:给一个只包含“(”“(”“(”和“)”“)”“)”的字符串sss,且保证它是平衡的(就是括号匹配的意思)。然后有qqq个询问,第iii次询问把s[qi]s[q_i]s[qi]进行翻转,让你求出最小的下标pospospos,使得翻转s[pos]s[pos]s[pos]后,字符串sss的括号依然是平衡的...原创 2020-03-07 23:35:36 · 173 阅读 · 0 评论 -
codeforces 1295E Permutation Separation 思维+线段树
https://vjudge.net/problem/CodeForces-1295E题目大意:p1,p2……pnp_1,p_2……p_np1,p2……pn为nnn的某个全排列,aia_iai为移动pip_ipi所需要的花费,你可以选取任意k,1<=k<nk,1<=k<nk,1<=k<n,把序列ppp分成两部分,即p1,……,pkp_1,……,p_k...原创 2020-02-07 18:40:48 · 334 阅读 · 0 评论 -
CSU 1811Intersection 线段树+启发式合并
http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1811Bobo has a tree with n vertices numbered by 1,2,…,n and (n-1) edges. The i-th vertex has color c i, and the i-th edge connects vertices a i and ...原创 2020-01-11 18:52:23 · 157 阅读 · 0 评论 -
洛谷 P2023 [AHOI2009]维护序列 线段树(区间加法+区间乘法)
https://www.luogu.org/problem/P2023题目描述老师交给小可可一个维护数列的任务,现在小可可希望你来帮他完成。 有长为N的数列,不妨设为a1,a2,…,aN 。有如下三种操作形式:(1)把数列中的一段数全部乘一个值;(2)把数列中的一段数全部加一个值;(3)询问数列中的一段数的和,由于答案可能很大,你只需输出这个数模P的值。输入格式第一行两个整数N和P(...原创 2019-10-25 23:38:21 · 229 阅读 · 0 评论 -
洛谷 P1198 [JSOI2008]最大数 线段树
https://www.luogu.org/problem/P1198题目描述现在请求你维护一个数列,要求提供以下两种操作:1、 查询操作。语法:Q L功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值。限制:L不超过当前数列的长度。(L>0)2、 插入操作。语法:A n功能:将n加上t,其中t是最近一次查询操作的答案(如果还未执行过查询操作,则(t=0),并将所...原创 2019-10-25 23:14:58 · 165 阅读 · 0 评论 -
codeforces gym101630 Archery Tournament 线段树+set
http://codeforces.com/gym/101630题目大意:有nnn个事件依次发生,每个事件以(op,x,y)(op,x,y)(op,x,y)的形式给出,若op=1op=1op=1,代表以(x,y)(x,y)(x,y)为圆心建立一个半径为yyy的圆形靶子,数据保证所有的靶子都不相交,但是可能会相切;若op=2op=2op=2,代表此时在(x,y)(x,y)(x,y)处进行一次射击,...原创 2019-10-23 15:49:02 · 343 阅读 · 0 评论 -
HDU 5692 Snacks dfs序+线段树
http://acm.hdu.edu.cn/showproblem.php?pid=5692百度科技园内有n个零食机,零食机之间通过n−1条路相互连通。每个零食机都有一个值v,表示为小度熊提供零食的价值。由于零食被频繁的消耗和补充,零食机的价值v会时常发生变化。小度熊只能从编号为0的零食机出发,并且每个零食机至多经过一次。另外,小度熊会对某个零食机的零食有所偏爱,要求路线上必须有那个零食...原创 2019-08-08 17:59:09 · 199 阅读 · 0 评论 -
HDU 6547 Tree 树链剖分+线段树区间开根区间求和
http://acm.hdu.edu.cn/showproblem.php?pid=6547wls 有三棵树,树上每个节点都有一个值 ai,现在有 2 种操作:1. 将一条链上的所有节点的值开根号向下取整;2. 求一条链上值的和;链的定义是两点之间的最短路。Input第一行两个数 n, q 分别代表树上点的数量和操作数量。第二行 n 个整数,第 i 个数代表第 i 个点的值 ai。...原创 2019-08-02 11:27:24 · 331 阅读 · 1 评论 -
UOJ 228 基础数据结构练习题 线段树区间开根+区间求和
http://uoj.ac/problem/228sylvia 是一个热爱学习的女孩子,今天她想要学习数据结构技巧。在看了一些博客学了一些姿势后,她想要找一些数据结构题来练练手。于是她的好朋友九条可怜酱给她出了一道题。给出一个长度为 nn 的数列 AA,接下来有 mm 次操作,操作有三种:对于所有的 i∈[l,r] 将 Ai 变成 Ai+x。对于所有的 i∈[l,r] 将 Ai 变成 ⌊...原创 2019-08-02 10:59:43 · 470 阅读 · 0 评论 -
洛谷 P3373 【模板】线段树 2
https://www.luogu.org/problem/P3373题目描述如题,已知一个数列,你需要进行下面三种操作:1.将某区间每一个数乘上x2.将某区间每一个数加上x3.求出某区间每一个数的和输入格式第一行包含三个整数N、M、P,分别表示该数列数字的个数、操作的总个数和模数。第二行包含N个用空格分隔的整数,其中第i个数字表示数列第i项的初始值。接下来M行每行包含3或4个整...原创 2019-08-17 16:17:45 · 122 阅读 · 0 评论 -
HDU 4578 Transformation 线段树 区间加法 区间乘法 区间置数 维护区间和 区间平方和 区间立方和
http://acm.hdu.edu.cn/showproblem.php?pid=4578Yuanfang is puzzled with the question below:There are n integers, a 1, a 2, …, a n. The initial values of them are 0. There are four kinds of operation...原创 2019-07-27 19:36:46 · 494 阅读 · 0 评论 -
BZOJ 2157 旅游 树链剖分(边权)+线段树(单点修改 区间修改 区间求和 RMQ)
https://www.lydsy.com/JudgeOnline/problem.php?id=2157Ray 乐忠于旅游,这次他来到了T 城。T 城是一个水上城市,一共有 N 个景点,有些景点之间会用一座桥连接。为了方便游客到达每个景点但又为了节约成本,T 城的任意两个景点之间有且只有一条路径。换句话说, T 城中只有N − 1 座桥。Ray 发现,有些桥上可以看到美丽的景色,让人心情愉悦,...原创 2019-08-02 14:15:54 · 221 阅读 · 0 评论 -
codeforces 609F Frogs and mosquitoes 线段树+二分+multiset
http://codeforces.com/problemset/problem/609/FThere are n frogs sitting on the coordinate axis Ox. For each frog two values xi, ti are known — the position and the initial length of the tongue of the...原创 2019-08-10 15:50:00 · 287 阅读 · 0 评论 -
HDU 6356 Glad You Came 线段树
http://acm.hdu.edu.cn/showproblem.php?pid=6356Steve has an integer array a of length n (1-based). He assigned all the elements as zero at the beginning. After that, he made m operations, each of whic...原创 2019-08-10 17:20:15 · 129 阅读 · 0 评论 -
洛谷P1471 方差 线段树维护区间方差
https://www.luogu.org/problem/P1471展开题目背景滚粗了的HansBug在收拾旧数学书,然而他发现了什么奇妙的东西。题目描述蒟蒻HansBug在一本数学书里面发现了一个神奇的数列,包含N个实数。他想算算这个数列的平均数和方差。输入格式第一行包含两个正整数N、M,分别表示数列中实数的个数和操作的个数。第二行包含N个实数,其中第i个实数表示数列的第i项。...原创 2019-08-20 16:55:12 · 243 阅读 · 0 评论 -
codeforces 1198B Welfare State 线段树
http://codeforces.com/problemset/problem/1198/BThere is a country with n citizens. The i-th of them initially has ai money. The government strictly controls the wealth of its citizens. Whenever a cit...原创 2019-09-04 17:02:14 · 266 阅读 · 0 评论 -
2019亚洲区域赛徐州网络赛 E XKC's basketball team 线段树
https://nanti.jisuanke.com/t/41387XKC , the captain of the basketball team , is directing a train of nn team members. He makes all members stand in a row , and numbers them 1 \cdots n1⋯n from left to...原创 2019-09-07 18:55:23 · 553 阅读 · 0 评论 -
HDU 1698 线段树
http://acm.hdu.edu.cn/showproblem.php?pid=1698In 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 s...原创 2019-03-01 12:43:30 · 197 阅读 · 0 评论 -
BZOJ 2243 染色 树链剖分+线段树
https://www.lydsy.com/JudgeOnline/problem.php?id=2243给定一棵有n个节点的无根树和m个操作,操作有2类:1、将节点a到节点b路径上所有点都染成颜色c;2、询问节点a到节点b路径上的颜色段数量(连续相同颜色被认为是同一段),如“112221”由3段组成:“11”、“222”和“1”。请你写一个程序依次完成这m个操作。Inpu...原创 2019-08-01 13:25:50 · 218 阅读 · 0 评论 -
CodeChef DGCD Dynamic GCD 树链剖分+线段树维护gcd
https://www.codechef.com/problems/DGCDYou’re given a tree on N vertices. Each vertex has a positive integer written on it, number on the ith vertex being vi. Your program must process two types of qu...原创 2019-08-05 15:20:34 · 247 阅读 · 0 评论 -
HDU 3074 Multiply game 线段树区间乘法
http://acm.hdu.edu.cn/showproblem.php?pid=3074Tired of playing computer games, alpc23 is planning to play a game on numbers. Because plus and subtraction is too easy for this gay, he wants to do som...原创 2019-07-27 16:34:15 · 165 阅读 · 0 评论 -
CSU 2151 集训难度 线段树
http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2151Description小L正在组织acm暑假集训,但众所周知,暑假集训的萌新中有OI神犇,也有暑假才开始学算法的萌新,如果统一集训的难度,无法很好地让萌新们得到训练,所以小L想了一个办法,根据每次测试的情况,改变萌新们的集训难度。现在将萌新们编号为1到n,最初萌新们的集...原创 2019-05-29 18:10:25 · 169 阅读 · 0 评论 -
Codeforces 1000F 线段树+离线处理
http://codeforces.com/problemset/problem/1000/FYou are given an array aa consisting of nn integers, and qq queries to it. ii -th query is denoted by two integers lili and riri . For each query, you ...原创 2019-03-02 17:04:24 · 314 阅读 · 0 评论 -
POJ 2528 离散化+线段树
http://poj.org/problem?id=2528The 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...原创 2019-03-02 14:19:59 · 188 阅读 · 0 评论 -
HDU 6315 线段树
http://acm.hdu.edu.cn/showproblem.php?pid=6315In 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.T...原创 2019-03-01 17:24:04 · 170 阅读 · 0 评论 -
HDU 3577 线段树
http://acm.hdu.edu.cn/showproblem.php?pid=3577Chinese always have the railway tickets problem because of its' huge amount of passangers and stations. Now goverment need you to develop a new tickets ...原创 2019-03-01 11:12:56 · 161 阅读 · 0 评论 -
HDU 1166 线段树
http://acm.hdu.edu.cn/showproblem.php?pid=1166C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动...原创 2019-02-28 00:05:02 · 102 阅读 · 0 评论 -
POJ 3468 线段树
http://poj.org/problem?id=3468You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interv...原创 2019-02-27 23:41:43 · 232 阅读 · 0 评论 -
HDU 1754 线段树
http://acm.hdu.edu.cn/showproblem.php?pid=1754很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。这让很多学生很反感。不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。Input本题目包含多组测试,请处理到文件结束。在每个测试的第一行...原创 2019-02-27 17:26:27 · 116 阅读 · 0 评论 -
HYSBZ 1018 堵塞的交通traffic 线段树维护区间连通性
https://www.lydsy.com/JudgeOnline/problem.php?id=1018 有一天,由于某种穿越现象作用,你来到了传说中的小人国。小人国的布局非常奇特,整个国家的交通系统可以被看成是一个2行C列的矩形网格,网格上的每个点代表一个城市,相邻的城市之间有一条道路,所以总共有2C个城市和3C-2条道路。 小人国的交通状况非常槽糕。有的时候由于交通堵塞,两座城市之间...原创 2019-07-29 15:28:52 · 141 阅读 · 0 评论 -
codeforces 786B Legacy 线段树优化连边
http://codeforces.com/problemset/problem/786/BRick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad g...原创 2019-07-29 18:56:19 · 138 阅读 · 0 评论 -
codeforces 438 D The Child and Sequence 线段树区间取模
http://codeforces.com/problemset/problem/438/DAt the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particu...原创 2019-07-27 16:16:56 · 150 阅读 · 0 评论 -
acwing 246 区间最大公约数 线段树+树状数组+差分
https://www.acwing.com/problem/content/247/?time=1564925894116给定一个长度为N的数列A,以及M条指令,每条指令可能是以下两种之一:1、“C l r d”,表示把 A[l],A[l+1],…,A[r] 都加上 d。2、“Q l r”,表示询问 A[l],A[l+1],…,A[r] 的最大公约数(GCD)。对于每个询问,输出一个整数...原创 2019-08-05 00:01:51 · 435 阅读 · 0 评论 -
CodeForces 1187 D 树状数组
链接:http://codeforces.com/problemset/problem/1187/DYou are given an array a1,a2,…,an and an array b1,b2,…,bn.For one operation you can sort in non-decreasing order any subarray a[l…r]of the arr...原创 2019-07-22 10:48:57 · 313 阅读 · 0 评论 -
SPOJ GSS7 Can you answer these queries VII 树链剖分+线段树(方向)
https://www.spoj.com/problems/GSS7/en/题意翻译题目描述给定一棵树,有N(N≤100000)N(N \le 100000)N(N≤100000)个节点,每一个节点都有一个权值xi(∣xi∣≤10000)x_i (|x_i| \le 10000)xi(∣xi∣≤10000)你需要执行Q(Q≤100000)Q (Q \le 100000)Q(Q≤1000...原创 2019-08-03 10:49:41 · 281 阅读 · 0 评论 -
SP1716 GSS3 Can you answer these queries III 线段树维护最大连续子段和
https://www.luogu.org/problem/SP1716题意翻译nnn 个数,qqq 次操作操作0 x y把AxA_xAx 修改为yyy操作1 l r询问区间[l,r][l, r][l,r] 的最大子段和感谢 @Edgration 提供的翻译题目描述You are given a sequence A of N (N <= 50000) integers be...原创 2019-08-02 18:15:50 · 182 阅读 · 0 评论 -
HDU 5052 Yaoge’s maximum profit 树链剖分+线段树(考虑方向的合并)
http://acm.hdu.edu.cn/showproblem.php?pid=5052Yaoge likes to eat chicken chops late at night. Yaoge has eaten too many chicken chops, so that Yaoge knows the pattern in the world of chicken chops. Th...原创 2019-08-02 16:34:14 · 187 阅读 · 0 评论 -
洛谷 P3384 树链剖分+线段树
https://www.luogu.org/problem/P3384题目描述如题,已知一棵包含N个结点的树(连通且无环),每个节点上包含一个数值,需要支持以下操作:操作1: 格式: 1 x y z 表示将树从x到y结点最短路径上所有节点的值都加上z操作2: 格式: 2 x y 表示求树从x到y结点最短路径上所有节点的值之和操作3: 格式: 3 x z 表示将以x为根节点的子树...原创 2019-07-30 12:51:28 · 157 阅读 · 0 评论