数据结构——线段树 学习笔记
class seg_t {
private:
struct emm {
int l, r;
struct v;
};
vector<emm> a;
void push_up(int k) { }
void action(int k, int v) { }
void push_down(int k) { }
void build(vector<any> q, int k, int l, int r) {
a[k].l = l, a[k].r = r;
if (l == r) { return; }
int mid = l + (r - l >> 1);
build(q, k * 2, l, mid);
build(q, k * 2 + 1, mid + 1, r);
push_up(k);
}
void modify(int k, int p, int q, int v) {
auto &l = a[k].l, &r = a[k].r;
if (l >= p && r <= q) return void(action(k, v));
int mid = l + (r - l >> 1);
if (mid >= p) modify(k * 2, p, q, v);
if (mid + 1 <= q) modify(k * 2 + 1, p, q, v);
push_up(k);
}
int query(int k, int p, int q) {
auto &l = a[k].l, &r = a[k].r;
int mid = l + (r - l >> 1);
int res;
if (mid >= p) res += query(k * 2, p, q);
if (mid + 1 <= q) res += query(k * 2 + 1, p, q);
return res;
}
public:
};
然后参考:https://www.cnblogs.com/RainPPR/p/18066950/scanning
以及:https://www.cnblogs.com/RainPPR/p/17974548/segment-tree-2
没了。是不是很水?
标签:int,线段,mid,笔记,build,push,数据结构,void From: https://www.cnblogs.com/RainPPR/p/18067623/segment-tree