only update removed node if not covered anymore
This commit is contained in:
parent
61f468c150
commit
d99b517ed0
2 changed files with 6 additions and 3 deletions
4
main.cpp
4
main.cpp
|
@ -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);
|
||||
|
|
|
@ -72,7 +72,9 @@ void SegmentTree::add_coverage(Index node_idx) {
|
|||
|
||||
void SegmentTree::remove_coverage(Index node_idx) {
|
||||
--(_nodes[node_idx].coverage);
|
||||
update_covered_length(node_idx);
|
||||
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 {
|
||||
|
|
Loading…
Reference in a new issue