当前位置:网站首页>Segment tree and tree array template (copy and paste are really easy to use)
Segment tree and tree array template (copy and paste are really easy to use)
2022-06-29 17:36:00 【Elucidation】
Line segment tree
contain lazy Mark pushdown
struct segtree
{
struct tree {
int l, r;
//maintain something
}tr[N << 2];
inline void pushup(int u) {
//maintain something
}
inline void pushdown(tree& node, tree& le, tree* re) {
//maintain something
}
inline void pushdown(int u) {
//maintain something
}
void build(int u, int l, int r) {
tr[u] = {
l,r }; //assign something
if (l == r) {
tr[u] = {
l,r }; //assign something
return;
}
int mid = l + r >> 1;
build(ul, l, mid), build(ur, mid + 1, r);
pushup(u);
}
void modify(int u, int l, int r, int v) {
if (tr[u].l >= l && tr[u].r <= r) {
//return something
return;
}
int mid = tr[u].l + tr[u].r >> 1;
pushdown(u);
if (l <= mid)modify(ul, l, r, v);
if (r > mid)modify(ur, l, r, v);
pushup(u);
}
int query(int u, int l, int r) {
if (tr[u].l >= l && tr[u].r <= r) {
//return something
return 1;
}
int mid = tr[u].l + tr[u].r >> 1;
pushdown(u);
int t = 0;
if (l <= mid)t = query(ul, l, r);
if (r > mid)t = query(ur, l, r);
return t;
}
}tr;
Tree array
Maintain prefix and only , Section sum, Be careful n The scope of the
struct BIT
{
int tr[N];
inline void ub(int& x) {
x += x & (-x); }
inline void db(int& x) {
x -= x & (-x); }
inline void modify(int x, int t) {
for (; x <= n; ub(x))tr[x] += t; }
inline int query(int x) {
int res = 0;
for (; x > 0; db(x))res += tr[x];
return res;
}
}bt;
边栏推荐
- 填充每个节点的下一个右侧节点指针[利用好每个点->尽可能降低时空复杂度]
- R language uses GLM function to build Poisson logarithm linear regression model, processes three-dimensional contingency table data to build saturation model, uses exp function and coef function to ob
- How to create a virtual image
- R语言使用epiDisplay包的kap函数(kap.2.raters函数)计算Kappa统计量的值(总一致性、期望一致性)、对两个评分对象的结果进行一致性分析、评分的类别为多个类别
- Bottom level internal skill cultivation
- [the sixth operation of modern signal processing]
- 2020版KALI安装教程
- Bags of Binary Words for Fast Place Recognition in Image Sequenc
- 基于STM32F103ZET6库函数独立看门狗(IWDG)实验
- 育润多维发力慈善领域,勇抗企业公益大旗
猜你喜欢
随机推荐
人脸识别4-百度商用方案调研
Error:Connection refused: connect
About harbor private warehouse forgetting the login password
Walk with love, educate and run poor families, and promote public welfare undertakings
reflex
Mysql中锁的使用场景是什么
从居家办公中感悟适配器模式 | 社区征文
How to solve MySQL 1045 error in Linux
Face recognition 4- research on Baidu commercial solutions
R language uses user-defined functions to write deep learning leaky relu activation functions and visualize leaky relu activation functions
使用autoIt 上传文件
R语言使用epiDisplay包的kap函数(kap.2.raters函数)计算Kappa统计量的值(总一致性、期望一致性)、对两个评分对象的结果进行一致性分析、评分的类别为多个类别
L'intercepteur handlerinterceptor personnalisé permet l'authentification de l'utilisateur
2020版KALI安装教程
How MySQL queries character set codes of tables
0基础自学STM32(野火)——使用寄存器点亮LED——GPIO功能框图讲解
The R language inputs the distance matrix to the hclust function for hierarchical clustering analysis. The method parameter specifies the distance calculation method between two combined data points,
MySQL highly available cluster – MHA
What are the advantages of SaaS services
mysql. What is the concept of sock








