跳到正文

个人记录

珂朵莉树(ODT)模板

EuphoricStar约 1 分钟
原文
文章信息与版本

文章信息

发布
2021年4月17日
收录
2025年12月12日
更新
2026年11月22日
篇幅
约 1 分钟

版本

  1. v1当前
C++
struct node {
    int l, r;
    mutable ll v;
    node(int x, int y = -1, ll z = 0) : l(x), r(y), v(z) {} 
    bool operator < (const node &u) const {
        return l < u.l;
    }
};
set<node> s;

typedef set<node>::iterator IT;

IT split(int pos) {
    IT it = s.lower_bound(node(pos));
    if (it != s.end() && it->l == pos) {
        return it;
    }
    --it;
    int l = it->l, r = it->r;
    ll v = it->v;
    s.erase(it);
    s.insert(node(l, pos - 1, v));
    return s.insert(node(pos, r, v)).first;
}

void assign_val(int l, int r, ll v) {
    IT itr = split(r + 1), itl = split(l);
    s.erase(itl, itr);
    s.insert(node(l, r, v));
}
原文
存档评论2 条抓取于