only update removed node if not covered anymore

This commit is contained in:
Maximilian Keßler 2022-04-17 14:02:35 +02:00
parent 61f468c150
commit d99b517ed0
2 changed files with 6 additions and 3 deletions

View file

@ -22,10 +22,10 @@ int main() {
srand(987192345);
add_rect(0,0,5,4);
check_area(20);
// check_area(20);
add_rect(3,2,6,6);
check_area(28);
// check_area(28);
add_rect(1,-2,8,4);
check_area(52);

View file

@ -72,7 +72,9 @@ void SegmentTree::add_coverage(Index node_idx) {
void SegmentTree::remove_coverage(Index node_idx) {
--(_nodes[node_idx].coverage);
if(!_nodes[node_idx].covered()) {
update_covered_length(node_idx);
}
}
Index SegmentTree::left_child_idx(Index node_idx) {
@ -84,6 +86,7 @@ Index SegmentTree::right_child_idx(Index node_idx) {
}
void SegmentTree::update_covered_length(Index node_idx) {
assert(!_nodes[node_idx].covered());
if (is_leaf(node_idx)) {
_nodes[node_idx].covered_length = 0;
} else {