struct Node{
int l, r;
...
//根据题目加必要的信息
}tr[N * 4];
//pushup操作
void pushup(Node &u, Node &l, Node &r){
//对题意给定信息
//根据节点l,节点r进行维护节点u
}
// 重载, 简化代码
void pushup(int u){
pushup(tr[u], tr[u << 1], tr[u << 1 | 1]);
}
// 建线段树
void build(int u, int l, int r){
if(l == r) {};
else{
tr[u] = {l, r};
int mid = l + r >> 1;
build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
pushup(u);
}
}
// 单点修改操作
void modify(int u, int x, int v){
if(tr[u].l == x && tr[u].r == x) tr[u] = {};
else{
int mid = tr[u].l + tr[u].r >> 1;
if(x <= mid) modify(u << 1, x, v);
else modify(u << 1 | 1, x, v);
pushup(u);
}
}
//区间查询
Node query(int u, int l, int r){
if(tr[u].l >= l && tr[u].r <= r) return tr[u];
else{
int mid = tr[u].l + tr[u].r >> 1;
if(r <= mid) return query(u << 1, l, r);
else if(l > mid) return query(u << 1 | 1, l, r);
else{
auto left = query(u << 1, l, r);
auto right = query(u << 1 | 1, l, r);
Node res;
pushup(res, left, right);
return res;
}
}
}