Skip to content

Commit

Permalink
Update 715.Range-Module_segTree.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Jan 31, 2019
1 parent 8d65a9a commit 9ce8bb0
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions Segment_Tree/715.Range-Module/715.Range-Module_segTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,35 @@ class RangeModule {
return;
}

bool setStatus(int a, int b, bool T)
void setStatus(int a, int b, bool T)
{
if (a<=start && b>=end) // bottom condition 1: [a,b)>[start,end)
{
remove(left);
remove(right);
return status = T;
status = T;
return;
}
if (a>=end || b<=start) // bottom condition 2: [a,b) do not intersect with [start,end)
return status;
return;
int mid = start+(end-start)/2;
if (left==NULL) // no children? create them!
{
left = new SegTree(start,mid,status);
right = new SegTree(mid,end,status);
}
bool L = left->setStatus(a,b,T);
bool R = right->setStatus(a,b,T);
return status = L&&R;
left->setStatus(a,b,T);
right->setStatus(a,b,T);
status =left->status && right->status;
}

bool getStatus(int a, int b)
{
if (a<=start && b>=end) // bottom condition 1: [a,b)>[start,end)
return status;
if (a>=end || b<=start) // bottom condition 2: [a,b) do not intersect with [start,end)
if (a>=end || b<=start) // bottom condition 2: [a,b) do not intersect with [start,end)
return true;
if (left==NULL) // bottom condition 3: [a,b) intersect with [start,end)
if (left==NULL)
return status;
int mid = start+(end-start)/2;
bool L = left->getStatus(a,b);
Expand Down

0 comments on commit 9ce8bb0

Please sign in to comment.