-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2168 - Nested Ranges Check.cpp
More file actions
58 lines (49 loc) · 1.08 KB
/
2168 - Nested Ranges Check.cpp
File metadata and controls
58 lines (49 loc) · 1.08 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
56
57
58
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<tuple<int, int, int>> a(n);
vector<pair<int, int>> ans(n);
vector<int> suff(n + 1), pref(n + 1);
for (int i = 0; i < n; i++) {
int f, s;
cin >> f >> s;
a[i] = {f, s, i};
}
sort(a.begin(), a.end(), [](auto x, auto y) {
auto [fx, sx, tx] = x;
auto [fy, sy, ty] = y;
if (sx == sy) return fx < fy;
return sx > sy;
});
for (int i = n - 1; i >= 0; i--) suff[i] = max(suff[i + 1], get<0>(a[i]));
pref[0] = suff[0] + 1;
for (int i = 0; i < n; i++) pref[i + 1] = min(pref[i], get<0>(a[i]));
for (int i = 0; i < n; i++) {
auto [f, s, t] = a[i];
ans[t].first = f <= suff[i + 1] ? 1 : 0;
ans[t].second = f >= pref[i] ? 1 : 0;
}
for (auto [f, s] : ans) cout << f << " ";
cout << "\n";
for (auto [f, s] : ans) cout << s << " ";
cout << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
}
/**
*
4 8
1 6
3 6
2 4
*
*
*/