-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrdered_Set.cpp
More file actions
50 lines (42 loc) · 1.12 KB
/
Ordered_Set.cpp
File metadata and controls
50 lines (42 loc) · 1.12 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
#include <bits/stdc++.h>
using namespace std;
// Ordered Set & Ordered Map
// s.order_of_key(k) -> number of elements less than k
// *s.find_by_order(index) -> s[index]
#include <ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename R>
using ordered_map = tree<T, R, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void solve() {
int n;
cin >> n;
ordered_set<int> s;
for (int i = 0; i < n; i++) {
int v;
cin >> v;
s.insert(v);
}
cout << *s.find_by_order(0) << '\n';
cout << s.order_of_key(2) << '\n';
ordered_map<int, int> mp;
for (int i = 0; i < n; i++) {
int k, v;
cin >> k >> v;
mp[k] = v;
}
cout << mp.find_by_order(0)->second << endl;
cout << mp.order_of_key(2) << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}