当前位置:网站首页>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语言使用epiDisplay包的kap函数(kap.2.raters函数)计算Kappa统计量的值(总一致性、期望一致性)、对两个评分对象的结果进行一致性分析、评分的类别为多个类别
- linux中mysql 1045错误如何解决
- Sectigo ov pan domain name certificate is 1590 yuan a year easy to use
- Bags of Binary Words for Fast Place Recognition in Image Sequenc
- What are the usage scenarios for locks in MySQL
- Go语言多方式并发实现龟兔赛跑
- mysql查询视图命令是哪个
- Scenario solution for two modules calling each other in go
- 基于STM32F103ZET6库函数定时器中断实验
- LeetCode 每日一题——535. TinyURL 的加密与解密
猜你喜欢

Collaborative development of epidemic home outsourcing project 𞓜 community essay solicitation

The soft youth under the blessing of devcloud makes education "smart" in the cloud

【现代信号处理第六次作业】

PCB frame drawing - ad19

OpenFeign使用步骤 轮询策略与权重 log4j使用 openFeign拦截器的配置

How to solve MySQL 1045 error in Linux

传承中华美德,关注中老年大健康,育润奶粉敬老情浓

How to create a virtual image

从一个被应用商店坑了的BUG说起

mysql在linux中2003错误如何解决
随机推荐
About Kali using xshell connection
PCB板框的绘制——AD19
mysql如何查询表的字符集编码
与爱同行,育润走进贫困家庭,助推公益事业
Leetcode daily question - 535 Encryption and decryption of tinyurl
Epoll analysis
Bags of Binary Words for Fast Place Recognition in Image Sequenc
第42期:MySQL 是否有必要多列分区
疫情居家外包项目之协作开发| 社区征文
R language uses GLM of mass package The Nb function establishes the negative binomial generalized linear model, and the summary function obtains the summary statistical information of the negative bin
SCM系统是什么?供应链管理系统有哪些优势?
R语言将距离矩阵输入给hclust函数进行层次聚类分析,method参数指定两个组合数据点间的距离计算方式、plot函数可视化层次聚类的树状图(dendrogram)
2020版KALI安装教程
What is the function of MySQL cursors
selenium上传文件
C语言练习----指针字符串、链表
Younger sister Juan takes you to learn JDBC - 2-day dash Day1
设置双击运行 jar 文件
Multi mode concurrent implementation of tortoise and rabbit race in go language
The dplyr package filter function of R language filters the data in dataframe data through combinatorial logic (and logic). The content of one field is equal to one of the specified vectors, and the v