-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNested_Ranges_Check.cpp
More file actions
55 lines (48 loc) · 1.18 KB
/
Copy pathNested_Ranges_Check.cpp
File metadata and controls
55 lines (48 loc) · 1.18 KB
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 <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> t3;
int main() {
int n;
cin >> n;
vector<t3> ranges;
multiset<int> x;
multiset<int> y;
for (int i = 0; i < n; i++) {
int s, e;
cin >> s >> e;
ranges.push_back({s, e, i});
x.insert(e);
y.insert(e);
}
sort(ranges.begin(), ranges.end(), [](t3 a, t3 b) {
auto [s1, e1, i] = a;
auto [s2, e2, j] = b;
if (s1 == s2)
return e1 > e2;
return s1 < s2;
});
vector<int> contains(n);
for (auto [s, e, i] : ranges) {
x.erase(x.find(e));
contains[i] = x.upper_bound(e) != x.begin();
}
for (int i : contains)
cout << i << " ";
cout << endl;
sort(ranges.begin(), ranges.end(), [](t3 a, t3 b) {
auto [s1, e1, i] = a;
auto [s2, e2, j] = b;
if (s1 == s2)
return e1 < e2;
return s1 > s2;
});
vector<int> contained(n);
for (auto [s, e, i] : ranges) {
y.erase(y.find(e));
contained[i] = y.lower_bound(e) != y.end();
}
for (int i : contained)
cout << i << " ";
cout << endl;
return 0;
}