-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrdered Set.cpp
More file actions
23 lines (20 loc) · 817 Bytes
/
Copy pathOrdered Set.cpp
File metadata and controls
23 lines (20 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#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() {
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({3, 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;
}