oi-wiki 上 split 的代码是
auto split(int x) {
if (x > n) return odt.end();
auto it = --odt.upper_bound(Node_t{x, 0, 0});
if (it->l == x) return it;
int l = it->l, r = it->r, v = it->v;
odt.erase(it);
odt.insert(Node_t(l, x - 1, v));
return odt.insert(Node_t(x, r, v)).first;
}
而我使用这个代码会在某些题里RE,第一个问题是当 set 为空,odt.end() 会 RE,第二个是当 odt.upper_bound(Node_t{x, 0, 0}) == odt.begin() 时,对其自减后访问值会RE。这个怎么改?