
线段树
UCAS王小二
不念过去,不畏未来...
展开
-
玲珑杯 1149 - Buildings【线段树+尺取】
“玲珑杯”ACM比赛 Round #19题意: 给出n,k值,接下来一行是楼房的高度(序列不能排序),按照题中的公式求取满足条件的楼房对数; 思路: 本题无非是更新区间最大值,最小值,其次利用尺取的思想。每更新一个值(也就是r向前移动一位)就查询一次,满足条件时:sum += r - l (比赛时最小值查询写错了,好菜啊)#include<bits/stdc++.h>int p[200000原创 2017-07-30 09:35:27 · 1859 阅读 · 0 评论 -
Codeforces 620E New Year Tree【DFS序+线段树区间染色+二进制思维+位运算】
The New Year holidays are over, but Resha doesn’t want to throw away the New Year tree. He invited his best friends Kerim and Gural to help him to redecorate the New Year tree. The New Year tree is原创 2018-02-01 23:56:42 · 317 阅读 · 0 评论 -
HDU 1540【线段树区间合并】
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 line. Except t原创 2018-01-26 18:01:29 · 202 阅读 · 0 评论 -
POJ 2528【线段树染色+离散化】
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 cou...原创 2018-01-24 13:46:39 · 227 阅读 · 0 评论 -
NBUT - 1113【线段树单点修改】
In the traditional RMQ (Range Minimum Query) problem, we have a static array A. Then for each query (L, R) (L<=R), we report the minimum value among A[L], A[L+1], …, A[R]. Note that the indices sta...原创 2018-03-19 21:30:13 · 366 阅读 · 0 评论 -
Wannafly挑战赛13 E VVQ 与线段【二分预处理+线段树区间查询】
链接:https://www.nowcoder.com/acm/contest/80/E 来源:牛客网 题目描述 VVQ 最近迷上了线段这种东西 现在他手上有 n 条线段,他希望在其中找到两条有公共点的线段,使得他们的异或值最大。 定义线段的异或值为它们并的长度减他们交的长度 输入描述: 第一行包括一个正整数 n,表示 VVQ 拥有的线段条数。 接...原创 2018-04-08 21:26:00 · 348 阅读 · 0 评论 -
HDU 6301 Distinct Values【线段树||优先队列】
题意:给你一个区间[1,n][1,n][1,n],m个询问,每次询问[l,r][l,r][l,r],表示这段区间数字不相重,输出字典序最小的排列. 分析: 区间与区间的关系有三种:包含,相交,分离; 把包含区间段的可以去掉,只剩下两种。先按照左端排下序,用线段树维护填第i个位置的最小值,查询O(1)O(1)O(1),区间单点更新O(n∗lgn)O(n∗lgn)O(n*lgn).#incl...原创 2018-07-24 16:34:55 · 208 阅读 · 0 评论 -
HDU 6315 Naive Operations【线段树+lazy】
题意:给你一段固定的序列1~n,当作分母,两次操作:add,L,R,区间所有的分子+1;query,L,R,查询区间和a[i]/b[i](向下取整)a[i]/b[i](向下取整)a[i]/b[i](向下取整). 分析: 区间维护sum和lazy,暴力更新lazy会TLE。由于分母固定,那就维护一个区间sub[root]=min(b[i]−a[i]sub[root]=min(b[i]−a[i]s...原创 2018-07-26 09:32:42 · 955 阅读 · 0 评论 -
HDU 6356 Glad You Came【线段树lazy】
题意:(a,b)(a,b)(a,b)区间内的数 = max((a,b),val)max((a,b),val)max((a,b),val),初始为0,最后只有一次查询. 分析: 线段树维护区间最小值,lazy进行区间操作,要有个减枝过程:就是减掉区间(a,b)min>=val(a,b)min>=val(a,b)_{min}>=val的状态. #include <bits/...原创 2018-08-07 22:21:46 · 174 阅读 · 0 评论 -
HDU 6406 Taotao Picks Apples【线段树+离线】
题意:给你一个序列和q次询问,每次询问会替换一个值,让你求上升子序列(遇到大的一定拿,长度是一定的,并不是最长的); 分析:上去就是先离线排序,然后直接维护一个递增的序列,然后二分更改,最后bug才找到写死了。。。 维护一个从左到右的递增序列,再用单调队列维护一个从右到左的递减序列,并记录对于每一个位置的上升序列长度;然后对于每一次离线查询,左侧直接预处理O(1),右侧用线段树维护最靠近查询位...原创 2018-08-20 22:14:50 · 190 阅读 · 0 评论 -
POJ 3321 Apple Tree【DFS序+线段树】
Apple TreeDescriptionThere is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been carefully nurturing the原创 2017-10-27 20:52:18 · 482 阅读 · 0 评论 -
HDU 4027【线段树技巧题】
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 a value of end原创 2018-01-24 21:20:49 · 561 阅读 · 0 评论 -
HDU 3974 Assign the task【DFS序+线段树区间染色】
Problem Description There is a company that has N employees(numbered from 1 to N),every employee in the company has a immediate boss (except for the leader of whole company).If you are the immediat原创 2018-02-01 00:13:57 · 296 阅读 · 0 评论 -
hdu 1754 I Hate It【线段树入门+模板详解】
【创建线段树(初始化)】: 由于线段树是用二叉树结构储存的,而且是近乎完全二叉树的,所以在这里我使用了数组来代替链表上图中区间上面的红色数字表示了结构体数组中对应的下标。在完全二叉树中假如一个结点的序号(数组下标)为 I ,那么 (二叉树基本关系)I 的父亲为 I/2,I 的另一个兄弟为 I/2*2 或 I/2*2+1I 的两个孩子为 I*2 (原创 2017-07-23 18:05:12 · 408 阅读 · 0 评论 -
hdu 1166 敌兵布阵【入门线段树 & 树状数组】
敌兵布阵Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 93502 Accepted Submission(s): 39459Problem DescriptionC国的死对头A国这段时间正在进行军事演原创 2017-07-26 09:01:42 · 311 阅读 · 0 评论 -
nyoj 1185 最大最小值【线段树】
最大最小值 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 给出N个整数,执行M次询问。 对于每次询问,首先输入三个整数C、L、R: 如果C等于1,输出第L个数到第R个数之间的最小值;如果C等于2,输出第L个数到第R个数之间的最大值;如果C等于3,输出第L个数到第R个数之间的最小值与最大值的和。(包括第L个数和第R个数)。输入 首先输入一个整数T原创 2017-08-02 17:04:46 · 264 阅读 · 0 评论 -
hdu1556 Color the ball【树状数组 || 线段树 || 技巧*区间修改】
思路: 新生赛做过类似的题目,对【l,r】区间修改值,只需要l端加一,r+1端减一就好,最后正序相加输出;#include<cstdio>#include<cstring>#define max_n 100010int a[max_n];int main(){ int n,l,r; while(scanf("%d",&n) && n) { mems原创 2017-08-02 13:47:17 · 2379 阅读 · 0 评论 -
HDU 1698【线段树区间修改】
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. Now Pudge原创 2018-01-24 00:31:11 · 164 阅读 · 0 评论 -
POJ 3468 【线段树区间更新】
You 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 interval. The other is to ask for the su原创 2018-01-24 00:26:06 · 237 阅读 · 0 评论 -
ZOJ 1610【线段树区间染色】
Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones. Your task is counting the segments of different colors you can see at last.原创 2018-01-24 10:20:18 · 211 阅读 · 0 评论 -
hdu 4578 Transformation【线段树区间&思维】
Problem Description Yuanfang is puzzled with the question below: There are n integers, a1, a2, …, an. The initial values of them are 0. There are four kinds of operations. Operation 1: Add c原创 2018-01-31 14:41:50 · 356 阅读 · 0 评论 -
浅谈线段树+模板
推荐两篇线段树博文: 线段树之一; 线段树之二;小结: 线段树是一种二叉树,也可以说成是区间树,操作有:建树build,更新updata(单点+区间),查询query(单点+区间)。单点操作时把区间不断二分,用root指向数组下标;区间更新操作时,标记lazy,先对子树的根节点做更新,当用到的这个子树的时候,再把标记下推,同时递归时向上统计,更新区间;区间查询时,会有遍历的一个操作遇到l...原创 2018-01-31 15:40:23 · 474 阅读 · 0 评论 -
2018 南京网络赛 G. Lpl and Energy-saving Lamps【线段树】
G. Lpl and Energy-saving Lamps; 题意:每个月买m个灯,依次从1~n的房间去装灯,每个房间都有需要的灯数kikik_i,当你有灯数大于等于kikik_i时才能装。问你第q个月,装了几个房间,剩了多少盏灯? 分析: 按照kikik_i排序后,线段树维护区间最小编号(两个tag,房间编号和kikik_i)。 注意:预处理时,房间都装完后,就不在买灯,答案固定了。...原创 2018-09-05 10:51:47 · 313 阅读 · 0 评论