线段树
文章平均质量分 59
qianyri
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
HDU1754 I Hate It 线段树单点更新
HDU1754 I Hate It/*线段树单点更新 967MS 3580K */ #include <stdio.h> #include <algorithm> using namespace std; const int MAX=2*1e5+5; int tree[MAX*4]; void read(int &x)//读入优化 { int f=1;x=0...原创 2018-04-30 13:24:15 · 293 阅读 · 0 评论 -
POJ3468 A Simple Problem with Integers 线段树区间更新
POJ3468 A Simple Problem with Integers/*线段树区间更新 2000MS 4484K */ #include <stdio.h> #include <string.h> const int MAX=1e5+5; long long tree[MAX*4]; long long lazy[MAX*4];//延时数组 void read...原创 2018-04-30 13:51:27 · 247 阅读 · 0 评论 -
2018 UESTC Training for Data Structures 一棵像样的线段树
一棵像样的线段树设 last[x] 表示使 bi = x 的最大的 i,即 bi 中 x 最后出现的位置.这样问题就转换为 bi = min last[x]<i−ci{x},也就是满足 last[x] < i−ci 的最小的 x,其中 1 ≤x≤n+ 1,x∈N∗. 可以用线段树维护 last[1..(n+ 1)] 每个区间的最小值. 查询的时候给定一个值 v = i−ci,从最大的区...原创 2018-05-20 13:42:31 · 584 阅读 · 0 评论 -
2018 UESTC Training for Data Structures 一棵复杂的线段树
一棵复杂的线段树二分答案,设 mid 为当前考虑答案区间的中点. 构造数组 B[1..n],bi = sgn(ai−mid). 数组 B 中只有 0 或 1. 用线段树维护数组 B 每个区间 1 的个数,可以实现在 O(logn) 的时间内对区间进行排序. 懒惰标记用来表示该区间全部赋成 0 或是 1.对区间 [L,R] 排序: 1 查询出区间 [L,R] 有多少个 1,设为 c 2 将区间 [L...原创 2018-05-20 16:01:30 · 442 阅读 · 0 评论 -
HDU6315 Naive Operations 线段树+树状数组
HDU6315 线段树+树状数组 线段树维护a序列的最小值(初始值为b,多次查询区间最值,当区间最小值为0时更新树状数组 //982MS 4764K #include <bits/stdc++.h> #define mid (l+r)/2 #define lowbit(x) x&-x using namespace std; const int MAX=1e5+1;...原创 2018-07-26 11:28:58 · 263 阅读 · 0 评论 -
HDU5692 Snacks 树上DFS序+线段树
HDU5692 Snacks 无向图 G = (Vn,En-1)构成一棵树,因此根节点O到树上各个节点的路径唯一,用线段树维护各个节点到O节点的权值之和(称为x的前缀和),每个节点的权值变化影响它和它子树的前缀和。 DFS先序遍历初始化各点的前缀和并储存在线段树中,对于每个节点x的变化,更新x和x子树的前缀和。(DFS先序遍历序列中属于同一子树的节点在连续区间中) DFS序可以有效处理子树变...原创 2018-08-03 20:10:52 · 278 阅读 · 0 评论 -
线段树+平移扫描法求矩形面积
T^TOJ 长方形的并的面积 线段树维护[ 1 , n ]全区间大于0的节点的个数即为矩形的长度,线段之间的宽度即为矩形的宽度 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int MAX=1e3+5; struct node {...原创 2018-08-07 19:18:58 · 483 阅读 · 0 评论 -
权值线段树/主席树专题
权值线段树 HDU1396 Minimum Inversion Number 求序列最小逆序数 权值线段树单点更新区间查询 #include<bits/stdc++.h> using namespace std; const int MAX=5e3+5; int a[MAX],n; struct P { int l,r,v; }b[MAX<<2]; voi...原创 2018-09-18 20:30:08 · 352 阅读 · 0 评论 -
codeforce893 F. Subtree Minimum Query 线段树合并
F. Subtree Minimum Query 给定一棵树,每个节点都有自己的权值,对于每个询问,查询x的子树中与x深度差不超过y的节点的最小权值 对树上的每一个节点以深度建立动态线段树,父节点合并子节点的线段树,O(logn)查询 #include<bits/stdc++.h> using namespace std; const int MAX=1e5+5; const ...原创 2018-10-24 19:56:17 · 333 阅读 · 0 评论
分享