-
Notifications
You must be signed in to change notification settings - Fork 0
/
structure.cpp
55 lines (46 loc) · 1.61 KB
/
structure.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "include/structure.hpp"
#include "include/utils.hpp"
void Edge::addFeaibleRange(Range newRange){
std::vector<Range> newFeasible;
bool isNewRangeNotAdded = true;
for (const Range& nowRange : feasible)
if (nowRange.min < newRange.min && nowRange.max < newRange.min ||
nowRange.min > newRange.max && nowRange.max > newRange.max )
newFeasible.push_back(nowRange);
else {
newRange = {
MIN(nowRange.min, newRange.min),
MAX(nowRange.max, newRange.max)
};
if (isNewRangeNotAdded)
newFeasible.push_back(newRange);
else
newFeasible.back() = newRange;
isNewRangeNotAdded = false;
}
if (isNewRangeNotAdded)
for (int i = 0; i < newFeasible.size(); i++)
if (newFeasible[i].min > newRange.min){
newFeasible.insert(newFeasible.begin() + i, newRange);
isNewRangeNotAdded = false;
break;
}
if (isNewRangeNotAdded)
newFeasible.push_back(newRange);
feasible = std::move(newFeasible);
}
bool Edge::checkIsInRange(int start, int end) const {
int i = 1, n = feasible.size();
for (const Range& range : feasible){
int min = range.min + 1;
int max = range.max - 1;
if (i == 1 && isLeftMost)
min--;
if (i == n && isRightMost)
max++;
if (start >= min && end <= max)
return true;
i++;
}
return false;
}