当前位置:网站首页>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;
边栏推荐
- 跨境独立站语言unicode转希伯来语
- Leetcode daily question - 535 Encryption and decryption of tinyurl
- 序列检测器
- selenium 组合键操作
- Error:Connection refused: connect
- Understanding adapter mode from home office | community essay solicitation
- 外部自动(PLC启动机器人)
- Multi mode concurrent implementation of tortoise and rabbit race in go language
- 在线SQL转CSV工具
- R语言使用自定义函数编写深度学习Leaky ReLU激活函数、并可视化Leaky ReLU激活函数
猜你喜欢

LeetCode 每日一题——535. TinyURL 的加密与解密

selenium 文件上传方法
![[the sixth operation of modern signal processing]](/img/49/7844a00077e56fd4d73e3ba515f8a6.png)
[the sixth operation of modern signal processing]

育润多维发力慈善领域,勇抗企业公益大旗

PCB板框的绘制——AD19

0 basic self-study STM32 (wildfire) -- use register to light LED -- Explanation of GPIO function block diagram

关于日期相加减问题

Collaborative development of epidemic home outsourcing project 𞓜 community essay solicitation

Mysql中锁的使用场景是什么

mysql. What is the concept of sock
随机推荐
首批!腾讯云通过中国信通院政务协同平台解决方案能力评估
Redis 原理 - Sorted Set (ZSet)
C语言练习----指针字符串、链表
腾讯云发布自动化交付和运维产品Orbit,推动企业应用全面云原生化
【Try to Hack】Cookie和Session
Self taught structure (small turtle C language)
LeetCode 每日一题——535. TinyURL 的加密与解密
Walk with love, educate and run poor families, and promote public welfare undertakings
C language practice ---- pointer string and linked list
Collaborative development of epidemic home outsourcing project 𞓜 community essay solicitation
力扣今日题-535. TinyURL 的加密与解密
How to establish and use KUKA subroutines / functions
R语言将距离矩阵输入给hclust函数进行层次聚类分析,method参数指定两个组合数据点间的距离计算方式、plot函数可视化层次聚类的树状图(dendrogram)
Mysql高可用集群–MHA
分割回文串[dp + dfs组合]
0基础自学STM32(野火)——使用寄存器点亮LED——GPIO功能框图讲解
Error:Connection refused: connect
regular expression
Kubernetes部署Dashboard(WEB UI管理界面)
External automatic (PLC start robot)