Advertisement
AppajiC

2102. Sequentially Ordinal Rank Tracker

Dec 13th, 2021
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <ext/pb_ds/assoc_container.hpp>
  2. #include <ext/pb_ds/tree_policy.hpp>
  3. using namespace __gnu_pbds;
  4.  
  5. class Location {
  6. public:
  7.     string name;
  8.     int score;
  9.  
  10.     Location(string _name, int _score): name(_name), score(_score) {}
  11.    
  12.     bool operator<(const Location& rhs) const {
  13.         if (score != rhs.score)
  14.             return score > rhs.score;
  15.         return name < rhs.name;
  16.     }
  17. };
  18.  
  19. #define ordered_set tree<Location, null_type, less<Location>, rb_tree_tag, tree_order_statistics_node_update>
  20.  
  21. class SORTracker {
  22. public:
  23.     ordered_set arr;
  24.     int queryIndex = 0;
  25.     SORTracker() {
  26.     }
  27.    
  28.     void add(string name, int score) {
  29.         arr.insert(Location(name, score));
  30.     }
  31.    
  32.     string get() {
  33.         return arr.find_by_order(queryIndex++)->name;
  34.     }
  35. };
  36.  
  37. /**
  38.  * Your SORTracker object will be instantiated and called as such:
  39.  * SORTracker* obj = new SORTracker();
  40.  * obj->add(name,score);
  41.  * string param_2 = obj->get();
  42.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement