随笔分类 - 线段树
摘要:题链 解:带修改的查询包含第一个值的[1,n]的最长上升子序列; 线段树维护节点区间最大值以及区间包含最左值的最长上升子序列,则询问的答案就是根节点的信息 区间最大值p[rt].maxn很好维护,主要是维护 区间包含最左值的最长上升子序列 这里记为p[rt].upcnt; 显然对于每一个叶子节点([
阅读全文
摘要:OI-wiki 有个手绘图 三道模板题(同求第k小) //#include <bits/stdc++.h> //#include <ext/pb_ds/priority_queue.hpp> #include <stdio.h> #include <stdlib.h> #include <strin
阅读全文
摘要:题链 二分答案,将原数组中小于二分值的置0,大于等于的置1,则区间排序问题则可变为区间赋值问题 线段树维护区间和,记cnt为[l,r]区间的1的个数,区间升序排序[l,r]可以转为对[r-cnt+1,r]区间值变为1,[l,r-cnt]区间值变为0,区间降序同理 若所求pos的值为1,说明经过一轮排
阅读全文
摘要:题链 扫描线模板题 将每个星星扩展为一个矩形,长w-1,宽h-1,扩展的长度不同维护的东西也不同。 这样扩展结果是维护一个个点,如图 而后维护区间max,操作只有区间加减。 #include <bits/stdc++.h> #include <ext/pb_ds/priority_queue.hpp
阅读全文
摘要:题链 题意求区间最长连续子序列最大和 当数据存在负数时,不能单纯取三个地方的max,如: p[rt].maxn = max(p[ls].rmax+p[rs].lmax,max(p[rt].lmax,p[rt].rmax)); #include <bits/stdc++.h> #include <io
阅读全文
摘要:题链 该题洛谷题解区讲的都很好; 当询问时, l == r时,答案有可能不是true... (奇怪的坑) #include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <stdio.h> #include <st
阅读全文
摘要:题链 对于mark的引入: 如果不引入直接加,会出现某段区间被重复加的现象,要保证若某段区间被覆盖,则只需要加一次。 #include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <stdio.h> #inclu
阅读全文
摘要:题链 线段树记录第i个礼物与之相同的后一个礼物的位置; LL p[MS]; // 记录第i个礼物 后一个礼物位置 LL q[MS]; // 记录第i个礼物 前一个礼物位置 关于修改: 1.删除第pos个礼物:在线段树中将其置为INF(表示该礼物不存在),删除后该礼物左右所指向的礼物位置则需要更改;
阅读全文
摘要:题链 此题与洛谷P6242 【模板】线段树 3为孪生题 #include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <stdlib.
阅读全文
摘要:题链 此题即Picks loves segment tree增加询问历史最值 #include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #inclu
阅读全文
摘要:题链 关于修改: min修改:直接递归到节点(maxse < val < maxf),转化为对节点最大值的加减; add修改:划分为对 节点最大值 和 节点其余值 的加减; lazy标记 最大值的加减lamaxf 和 其余值的加减laoth 重点在于将 min修改 和 add修改 变为同一修改 #i
阅读全文
摘要:题链 关于修改:直接递归到节点(maxse < val < maxf),转化为只关于该节点最大值的加减; #include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <stdio.h> #include <st
阅读全文
摘要:题链 #include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <stdlib.h> using namespace std; #
阅读全文
摘要:题链 #include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <stdlib.h> using namespace std; #
阅读全文

浙公网安备 33010602011771号