-
Notifications
You must be signed in to change notification settings - Fork 0
/
nested-ranges-check.cpp
68 lines (63 loc) · 1.39 KB
/
nested-ranges-check.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
#include <bits/stdc++.h>
using namespace std;
// increasing second, decreasing first
bool isdf(tuple<int, int, int> a, tuple<int, int, int> b) {
auto [x1, y1, i] = a;
auto [x2, y2, j] = b;
if (y1 == y2) {
return x1 > x2;
}
return y1 < y2;
}
void contains_range(vector<tuple<int, int, int>>& p) {
vector<tuple<int, int, int>> ps(p);
sort(ps.begin(), ps.end(), isdf);
set<int> xs;
vector<int> ans(p.size());
for (auto [x, y, i]: ps) {
auto lower = xs.lower_bound(x);
ans[i] = lower != xs.end();
xs.insert(x);
}
for (auto [x, y, i]: p) {
cout << ans[i] << " ";
}
cout << "\n";
}
// increasing first, decreasing second
bool ifds(tuple<int, int, int> a, tuple<int, int, int> b) {
auto [x1, y1, i] = a;
auto [x2, y2, j] = b;
if (x1 == x2) {
return y1 > y2;
}
return x1 < x2;
}
void inside_range(vector<tuple<int, int, int>>& p) {
vector<tuple<int, int, int>> ps(p);
sort(ps.begin(), ps.end(), ifds);
set<int> ys;
vector<int> ans(p.size());
for (auto [x, y, i]: ps) {
auto lower = ys.lower_bound(y);
ans[i] = lower != ys.end();
ys.insert(y);
}
for (auto [x, y, i]: p) {
cout << ans[i] << " ";
}
cout << "\n";
}
int main() {
int n;
cin >> n;
vector<tuple<int, int, int>> p(n);
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
p[i] = {x, y, i};
}
contains_range(p);
inside_range(p);
return 0;
}