Skip to content

Commit 2d620d8

Browse files
authored
Create 2102.Sequentially-Ordinal-Rank-Tracker_v2.cpp
1 parent 7b0cd69 commit 2d620d8

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
*/

0 commit comments

Comments
 (0)