版本比较
FHQ_Treap
正文
增加 6 行删除 6 行
23 行未改动24252627282829303132333334353637262 行未改动全部展开3003013023033043043053063073085 行未改动31431531631731831831932032132281 行未改动40440540640740840840941041141212 行未改动4254264274284294294304314324337 行未改动23 行未改动 Node* ch[2]; // 左右儿子 int val, prio; // 值、优先级 int cnt; // 重复值计数 int siz; // 子树大小
Node(int _val) : val(_val), cnt(1), siz(1) { ch[0] = ch[1] = nullptr; prio = rnd(); } // 初始化
void upd_siz() { siz = cnt; if (ch[0] != nullptr) siz += ch[0]->siz; if (ch[1] != nullptr) siz += ch[1]->siz;262 行未改动全部展开 rmax = max(max(ch[1]->rmax, ch[1]->sum + val + ch[0]->rmax), 0ll); maxn = max(max(max(ch[0]->rmax + ch[1]->lmax, 0ll) + val, ch[0]->maxn), ch[1]->maxn); }}
inline void cover(int c) { val = c; sum = c * siz; lmax = rmax = max(sum, 0ll);5 行未改动 swap(ch[0], ch[1]); swap(lmax, rmax); to_rev ^= 1;}
inline void pushdown() { if (to_same) { if (ch[0] != nullptr) ch[0]->cover(val); if (ch[1] != nullptr) ch[1]->cover(val);81 行未改动 auto tmp2 = split(tmp.second, len); if (tmp2.first != nullptr) tmp2.first->cover(c); root = merge(merge(tmp.first, tmp2.first), tmp2.second);}
inline void reverse(int pos, int len) { auto tmp = split(root, pos - 1); auto tmp2 = split(tmp.second, len); if (tmp2.first != nullptr) tmp2.first->rev();12 行未改动 int ret = (tmp2.first == nullptr ? 0 : tmp2.first->sum); root = merge(merge(tmp.first, tmp2.first), tmp2.second); return ret;}
inline int max_sum() { if (root != nullptr) return root->maxn; return 0;}7 行未改动