diff --git a/main.cpp b/main.cpp index a7b7703..c89a89a 100644 --- a/main.cpp +++ b/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); diff --git a/segment_tree.h b/segment_tree.h index 2ee53d3..2d399e3 100644 --- a/segment_tree.h +++ b/segment_tree.h @@ -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 {