-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path732.cpp
69 lines (64 loc) · 2.15 KB
/
732.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
__________________________________________________________________________________________________
sample 72 ms submission
static auto _=[](){
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
return 0;
}();
class MyCalendarThree {
private:
map<int, int> count = {{-1,0}};
int res = 0;
public:
int book(int s, int e) {
auto start = count.emplace(s, (--count.lower_bound(s))->second).first;
auto end = count.emplace(e, (--count.lower_bound(e))->second).first;
for (auto i = start; i != end; ++i) res = max(res, ++(i->second));
return res;
}
};
/**
* Your MyCalendarThree object will be instantiated and called as such:
* MyCalendarThree* obj = new MyCalendarThree();
* int param_1 = obj->book(start,end);
*/
__________________________________________________________________________________________________
sample 23304 kb submission
class MyCalendarThree {
public:
MyCalendarThree() : elementNumber(0) {
}
int book(int start, int end) {
startIndices.push_back(start);
sort(startIndices.begin(), startIndices.end());
endIndices.push_back(end);
sort(endIndices.begin(), endIndices.end());
elementNumber += 2;
int maxBooking = 0;
int currentBooking = 0;
int startPosition = 0;
int endPosition = 0;
for (int i=0; i<elementNumber-1; ++i) {
if (startPosition == startIndices.size()
|| startIndices[startPosition] >= endIndices[endPosition]) {
++endPosition;
--currentBooking;
} else {
++startPosition;
++currentBooking;
maxBooking = max(maxBooking, currentBooking);
}
}
return maxBooking;
}
private:
vector<int> startIndices;
vector<int> endIndices;
int elementNumber;
};
/**
* Your MyCalendarThree object will be instantiated and called as such:
* MyCalendarThree obj = new MyCalendarThree();
* int param_1 = obj.book(start,end);
*/
__________________________________________________________________________________________________