-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOrdered Set
More file actions
22 lines (21 loc) · 810 Bytes
/
Ordered Set
File metadata and controls
22 lines (21 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename R> using o_map = tree<T, R, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main() {
int i, j, k, n, m;
o_set<int>se;
se.insert(1);
se.insert(2);
cout << *se.find_by_order(0) << endl; ///k th element
cout << se.order_of_key(2) << endl; ///number of elements less than k
o_map<int, int>mp;
mp.insert({1, 10});
mp.insert({2, 20});
cout << mp.find_by_order(0)->second << endl; ///k th element
cout << mp.order_of_key(2) << endl; ///number of first elements less than k
return 0;
}