![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
【线段树/树状数组/RMQ】
riba2534
没有谁生来就是神牛,而千里之行,始于足下!
展开
-
H. Ryuji doesn't want to study(ACM-ICPC 2018 徐州赛区网络预赛,树状数组)
描述 Ryuji is not a good student, and he doesn’t want to study. But there are n books he should learn, each book has its knowledge a[i]. Unfortunately, the longer he learns, the fewer he gets....原创 2018-09-10 23:42:55 · 299 阅读 · 0 评论 -
2017第八届蓝桥杯省赛-大学A组 油漆面积(线段树,扫描线,离散化,矩形面积并)
描述 X星球的一批考古机器人正在一片废墟上考古。 该区域的地面坚硬如石、平整如镜。 管理人员为方便,建立了标准的直角坐标系。 每个机器人都各有特长、身怀绝技。它们感兴趣的内容也不相同。 经过各种测量,每个机器人都会报告一个或多个矩形区域,作为优先考古的区域。 矩形的表示格式为(x1,y1,x2,y2),代表矩形的两个对角点坐标。 为了醒目,总部要求对所有机器人...原创 2018-03-13 19:38:00 · 3143 阅读 · 2 评论 -
洛谷-P3373 线段树 2(线段树,区间更新,lazy标记,好题)
题目描述 如题,已知一个数列,你需要进行下面三种操作: 1.将某区间每一个数乘上x 2.将某区间每一个数加上x 3.求出某区间每一个数的和输入输出格式 输入格式: 第一行包含三个整数N、M、P,分别表示该数列数字的个数、操作的总个数和模数。 第二行包含N个用空格分隔的整数,其中第i个数字表示数列第i项的初始值。 接下...原创 2018-03-15 20:44:51 · 616 阅读 · 0 评论 -
POJ2528 Mayor's posters(线段树区间更新,离散化)
题目:Mayor's postersTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 66425 Accepted: 19177DescriptionThe citizens of Bytetown, AB, could not stand that the candidates in the mayoral election ca...原创 2017-08-05 00:45:53 · 599 阅读 · 0 评论 -
Educational Codeforces Round 37 (Rated for Div. 2) F. SUM and REPLACE(线段树,区间更新)
描述 Let D(x) be the number of positive divisors of a positive integer x. For example, D(2) = 2 (2 is divisible by 1 and 2), D(6) = 4 (6 is divisible by 1, 2, 3 and 6). You are given an a...原创 2018-02-09 00:52:39 · 345 阅读 · 0 评论 -
POJ2155 Matrix(二维树状数组)
Description Given 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 We can change the matrix原创 2018-01-25 17:54:21 · 312 阅读 · 0 评论 -
vijos-1512 SuperBrother打鼹鼠(二维树状数组)
背景 SuperBrother在机房里闲着没事干(再对比一下他的NOIP,真是讽刺啊……),于是便无聊地开始玩“打鼹鼠”……描述 在这个“打鼹鼠”的游戏中,鼹鼠会不时地从洞中钻出来,不过不会从洞口钻进去(鼹鼠真胆大……)。洞口都在一个大小为n(n输入格式 每个输入文件有多行。 第一行,一个数n,表示鼹鼠的范围。 以后每一行开头都有一个原创 2018-01-25 16:45:08 · 568 阅读 · 0 评论 -
HDU5239 Doom(线段树,区间更新,区间平方)
Problem Description THE END IS COMINGGGGGG! Mike has got stuck on a mystery machine. If he cannot solve this problem, he will go to his doom. This machine is consist of n cells, and a sc原创 2017-12-02 12:46:22 · 669 阅读 · 0 评论 -
BZOJ3211 花神游历各国(线段树,区间开根号)
描述InputOutput 每次x=1时,每行一个整数,表示这次旅行的开心度Sample Input41 100 5 551 1 22 1 21 1 22 2 31 1 4Sample Output1011111Hint 对于100%的数据, n ≤ 100000,m≤200000 ,data[i]非负且小于10^9思路题意很好理解,就是给了一段区间,有两种操作,一原创 2017-12-01 21:23:03 · 1634 阅读 · 0 评论 -
HDU4027 Can you answer these queries?(线段树区间更新,区间开根号)
题目:Can you answer these queries?Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 17754 Accepted Submission(s): 4163Problem D原创 2017-08-05 15:47:24 · 390 阅读 · 0 评论 -
Codeforces Round #446 (Div. 2) B. Wrath(线段树,RMQ,区间最值)
Description Hands that shed innocent blood! There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front原创 2017-11-18 13:46:33 · 358 阅读 · 0 评论 -
POJ3667 Hotel(线段树区间合并+lazy标记)
Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever the competent travel ag...原创 2018-04-07 22:52:45 · 322 阅读 · 0 评论 -
HihoCoder - 1710 等差子数列(线段树区间最值记录位置,思路)
描述 给定N个整数A1, A2, … AN,小Hi会询问你M个问题。 对于每个问题小Hi给出两个整数L和R(L ≤ R),请你找出[AL, AL+1, AL+2, … AR]中最长的等差连续子数列,并输出其长度。 例如[2, 3, 5, 7, 9]中最长的等差连续子数列是[3, 5, 7, 9]长度为4。输入 第一行包含两个整数N和M。 ...原创 2018-04-05 10:16:02 · 585 阅读 · 0 评论 -
CodeForces - 877E Danil and a Part-time Job(线段树区间异或,lazy标记,dfs序)
描述 Danil 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 acycli...原创 2018-04-20 09:37:59 · 352 阅读 · 0 评论 -
HDU6444 Neko's loop(2018CCPC网络赛,线段树,思路)
Problem Description Neko has a loop of size n. The loop has a happy value ai on the i−th(0≤i≤n−1) grid. Neko likes to jump on the loop.She can start at anywhere. If she stands at i−th grid,...原创 2018-09-06 11:30:00 · 442 阅读 · 0 评论 -
HDU6447 YJJ's Salesman(2018CCPC网络赛,线段树,思路)
Problem Description YJJ is a salesman who has traveled through western country. YJJ is always on journey. Either is he at the destination, or on the way to destination. One day, he is going to ...原创 2018-09-07 20:12:56 · 348 阅读 · 0 评论 -
HDU6406 Taotao Picks Apples(2018HDU多校联赛第八场,线段树)
Problem Description There is an apple tree in front of Taotao’s house. When autumn comes, n apples on the tree ripen, and Taotao will go to pick these apples. When Taotao picks apples, Taotao s...原创 2018-08-17 10:19:35 · 499 阅读 · 0 评论 -
HDU6356 Glad You Came(2018HDU多校联赛第五场,线段树)
Problem Description Steve 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 which is to update an inter...原创 2018-08-07 19:16:39 · 291 阅读 · 0 评论 -
HDU6315 Naive Operations(2018HDU多校联赛第二场,线段树)
Problem 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 ...原创 2018-07-26 16:22:38 · 518 阅读 · 0 评论 -
牛客网暑期ACM多校训练营(第一场)J. Different Integers(树状数组,离线处理)
题目描述 Given a sequence of integers a1, a2, …, an and q pairs of integers (l1, r1), (l2, r2), …, (lq, rq), find count(l1, r1), count(l2, r2), …, count(lq, rq) where count(i, j) is the number of diff...原创 2018-07-20 11:20:50 · 373 阅读 · 0 评论 -
SPOJ DQUERY - D-query(树状数组,离线查询,区间不同元素个数)
描述 Given a sequence of n numbers a1, a2, …, an and a number of d-queries. A d-query is a pair (i, j) (1 ≤ i ≤ j ≤ n). For each d-query (i, j), you have to return the number of distinct eleme...原创 2018-07-20 11:04:31 · 493 阅读 · 0 评论 -
HDU2852 KiKi's K-Number(值域线段树,求线段树第k大)
Problem Description For the k-th number, we all should be very familiar with it. Of course,to kiki it is also simple. Now Kiki meets a very similar problem, kiki wants to design a container,...原创 2018-07-18 17:04:15 · 440 阅读 · 0 评论 -
NYOJ1217 GLaDOS的耳机(线段树,区间染色)
描述 GLaDOS是个耳机控。对于他来说,已经不满足于只是听出供电设备是水电、核电还是火电了。GLaDOS有更大的目标,他想听出宇宙中最神秘的代号为"Y_A_FL"的声音。为了实现这个目的,GLaDOS决定为他的耳机加工升级。但是笨手笨脚的GLaDOS表示加工升级神马的太困难了。于是GLaDOS想请JX为他解决这个难题,而懒得不能再懒得JX又把这个难题交给了你,你能帮这两个二货解决这个...原创 2018-05-04 08:46:30 · 241 阅读 · 0 评论 -
ZOJ3635 Cinema in Akiba(线段树)
描述 Cinema in Akiba (CIA) is a small but very popular cinema in Akihabara. Every night the cinema is full of people. The layout of CIA is very interesting, as there is only one row so that ev...原创 2018-05-09 10:18:06 · 329 阅读 · 0 评论 -
HDU1754 I Hate It(线段树单点更新,区间最大值,zkw线段树)
题目:I Hate ItTime Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 73750 Accepted Submission(s): 28451Problem Description很多学校流原创 2017-04-24 16:00:12 · 636 阅读 · 0 评论 -
NYOJ116 士兵杀敌(二)(线段树区单点更新,区间求和,zkw线段树)
题目:士兵杀敌(二)时间限制:1000 ms | 内存限制:65535 KB难度:5描述南将军手下有N个士兵,分别编号1到N,这些士兵的杀敌数都是已知的。小工是南将军手下的军师,南将军经常想知道第m号到第n号士兵的总杀敌数,请你帮助小工来回答南将军吧。南将军的某次询问之后士兵i可能又杀敌q人,之后南将军再询问的时候,需要考原创 2017-04-26 18:00:51 · 479 阅读 · 0 评论 -
Zkw线段树-介绍及各种常用操作
介绍Zkw线段是是一种非递归式线段树,Zkw线段树有很多优点:1. 代码简短;2. 纯天然非递归;3. 常数小(尤其在差分区间更新时)。 它采用堆结构,构造一颗满二叉树(也可以说是完全二叉树),而二叉树的最后一层则是各个节点注意:zkw线段树必须是点树,即完全闭区间 普通线段树中的修改需要去查询节点,并分为三类: 完全覆盖,在左区间,在右区间 那么换个方法,自底向上更新呢? 这就是原创 2017-10-05 17:09:18 · 2541 阅读 · 0 评论 -
HDU2795 Billboard(线段树单点更新,区间最大值)
题目:BillboardTime Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 21472 Accepted Submission(s): 8852Problem DescriptionAt th原创 2017-04-25 19:32:15 · 441 阅读 · 0 评论 -
HDU1166 敌兵布阵(线段树单点更新,区间求和)(代码风格修正版)
题目:敌兵布阵Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 87366 Accepted Submission(s): 36806Problem DescriptionC国的死对头A国这段原创 2017-04-24 11:04:16 · 496 阅读 · 0 评论 -
NSWOJ1204 士兵杀敌(一)(树状数组)
题目:1204 - 士兵杀敌(一)时间限制:1秒 内存限制:128兆4 次提交 1 次通过提交题目描述南将军手下有N个士兵,分别编号1到N,这些士兵的杀敌数都是已知的。小工是南将军手下的军师,南将军现在想知道第m号到第n号士兵的总杀敌数,请你帮助小工来回答南将军吧。注意,南将军可能会问很多次问题。输入只有一组测试数据第原创 2016-11-10 17:16:29 · 1538 阅读 · 0 评论 -
POJ3067 Japan(树状数组,逆序数)
题目:JapanTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 27465 Accepted: 7428DescriptionJapan plans to welcome the ACM ICPC World Finals an原创 2017-04-21 18:51:43 · 462 阅读 · 0 评论 -
HDU1556 Color the ball(树状数组+抖机灵)
题目:Color the ballTime Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 19338 Accepted Submission(s): 9651Problem DescriptionN原创 2017-04-21 17:52:21 · 494 阅读 · 0 评论 -
HDU1166 敌兵布阵(树状数组)
题目:敌兵布阵Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 87245 Accepted Submission(s): 36750Problem DescriptionC国的死对头A国这段原创 2017-04-21 16:43:24 · 312 阅读 · 0 评论 -
HDU1698 Just a Hook(线段树+成段更新+lazy标记)
题目:Just a HookTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 31325 Accepted Submission(s): 15420Problem DescriptionIn原创 2017-05-01 20:10:30 · 528 阅读 · 0 评论 -
POJ2828 Buy Tickets(线段树,单点更新)
题目:Buy TicketsTime Limit: 4000MS Memory Limit: 65536KTotal Submissions: 19959 Accepted: 9860DescriptionRailway tickets were difficult to buy around原创 2017-05-01 16:21:41 · 473 阅读 · 0 评论 -
HDU1394 Minimum Inversion Number(线段树单点更新,暴力,逆序数)
题目:Minimum Inversion NumberTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19790 Accepted Submission(s): 11891Problem Descr原创 2017-04-30 20:50:30 · 491 阅读 · 0 评论 -
NYOJ228 士兵杀敌(五)(思路)
题目:士兵杀敌(五)时间限制:2000 ms | 内存限制:65535 KB难度:5描述南将军麾下有百万精兵,现已知共有M个士兵,编号为0~M,每次有任务的时候,总会有一批编号连在一起人请战(编号相近的人经常在一块,相互之间比较熟悉),最终他们获得的军功,也将会平分到每个人身上,这样,有时候,计算他们中的哪一个人到底有多少军功就是一个比较原创 2017-04-28 16:59:53 · 1266 阅读 · 0 评论 -
RMQ (Range Minimum/Maximum Query)算法
转载自:http://blog.csdn.net/niushuai666/article/details/66246721. 概述RMQ(Range Minimum/Maximum Query),即区间最值查询,是指这样一个问题:对于长度为n的数列A,回答若干询问RMQ(A,i,j)(i,j算法。当然,该问题也可以用线段树(也叫区间树)解决,算法复杂度为:O(N)~O(转载 2017-04-26 20:23:24 · 370 阅读 · 0 评论 -
NYOJ119 士兵杀敌(三)(RMQ算法)
题目:士兵杀敌(三)时间限制:2000 ms | 内存限制:65535 KB难度:5描述南将军统率着N个士兵,士兵分别编号为1~N,南将军经常爱拿某一段编号内杀敌数最高的人与杀敌数最低的人进行比较,计算出两个人的杀敌数差值,用这种方法一方面能鼓舞杀敌数高的人,另一方面也算是批评杀敌数低的人,起到了很好的效果。所以,南将军经常问军师原创 2017-04-26 21:23:02 · 465 阅读 · 0 评论 -
HDU1255 覆盖的面积(线段树,离散化,扫描线,矩形面积交)
题目:覆盖的面积Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6037 Accepted Submission(s): 3039Problem Description给定平面上若干矩形,原创 2017-08-07 18:05:31 · 475 阅读 · 0 评论