-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathordered_set.cpp
More file actions
40 lines (29 loc) · 816 Bytes
/
ordered_set.cpp
File metadata and controls
40 lines (29 loc) · 816 Bytes
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
#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;
typedef tree<
int, // data type
null_type,
less<int>, // less_equal for multiset
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
/*
methods
- order_of_key(val) -> returns the number of elements strictly less than val in the set
- find_by_order(idx) -> returns the pointer to element at index "idx". Make sure you * to get the element.
*/
ordered_set t;
t.insert(0);
t.insert(1);
t.insert(1);
t.insert(5);
t.insert(10);
cout << *t.find_by_order(2) << endl;
cout << t.order_of_key(2) << endl;
}