File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Heap/2102.Sequentially-Ordinal-Rank-Tracker Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < ext/pb_ds/assoc_container.hpp> // Common file
2
+ #include < ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
3
+ using namespace __gnu_pbds ;
4
+
5
+ typedef tree<
6
+ pair<int , string> ,
7
+ null_type,
8
+ less<pair<int , string>>,
9
+ rb_tree_tag,
10
+ tree_order_statistics_node_update>
11
+ ordered_set;
12
+
13
+ class SORTracker {
14
+ ordered_set Set;
15
+ int i = 0 ;
16
+ public:
17
+ SORTracker ()
18
+ {
19
+ }
20
+
21
+ void add (string name, int score)
22
+ {
23
+ Set.insert ({-score, name});
24
+ }
25
+
26
+ string get ()
27
+ {
28
+ i++;
29
+ return Set.find_by_order (i-1 )->second ;
30
+ }
31
+ };
32
+
33
+ /* *
34
+ * Your SORTracker object will be instantiated and called as such:
35
+ * SORTracker* obj = new SORTracker();
36
+ * obj->add(name,score);
37
+ * string param_2 = obj->get();
38
+ */
You can’t perform that action at this time.
0 commit comments