Made treap size comparisons inclusive

This commit is contained in:
Matúš Púll 2025-03-28 16:52:19 +01:00
parent 1e1a147116
commit d6e22b641b

View file

@ -32,7 +32,7 @@ public:
two_lines split(line *l, count_type k) {
if(l == nullptr) return {nullptr, nullptr};
if(get_size(l->left) > k) {
if(get_size(l->left) >= k) {
// In the left subtree
auto two = split(l->left, k);
l->size -= get_size(two.first);
@ -45,6 +45,7 @@ public:
return {l, two.second};
}
}
// Join two treaps
// Hopefully with working sizes
line* join(line *a, line *b) {
@ -63,6 +64,7 @@ public:
}
}
line* join(two_lines two) { return join(two.first, two.second); }
// Find k-th line of file
line* find(line* l, count_type k) {
if(l == nullptr) return nullptr;