Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using pis = pair<int, string>;
- bool cmp1(const pis &a, const pis &b)
- {
- if (a.first != b.first)
- return a.first < b.first;
- return a.second > b.second;
- }
- bool cmp2(const pis &a, const pis &b)
- {
- if (a.first != b.first)
- return a.first > b.first;
- return a.second < b.second;
- }
- class SORTracker
- {
- priority_queue<pis, vector<pis>, decltype(&cmp1)> pq1;
- priority_queue<pis, vector<pis>, decltype(&cmp2)> pq2;
- int curr;
- public:
- SORTracker()
- {
- printf("construction\n");
- curr = 0;
- }
- void add(string name, int score)
- {
- printf("add\n");
- auto ele = pis{score, name};
- if (pq2.empty()) {
- printf("pq1 push\n");
- pq1.push(ele);
- return;
- }
- printf("cmp2\n");
- if (cmp2(ele, pq2.top())) {
- pq1.push(ele);
- } else {
- pq2.push(ele);
- }
- }
- string get()
- {
- printf("get pq2.size():%lu\n", pq2.size());
- /*
- while (pq2.size() > curr + 1) {
- auto ele = pq2.top();
- pq2.pop();
- pq1.push(ele);
- }
- while (pq2.size() < curr + 1) {
- auto ele = pq1.top();
- pq1.pop();
- pq2.push(ele);
- }
- ++curr;
- auto h = pq2.top();
- return h.second;
- */
- return "";
- }
- };
- /**
- * Your SORTracker object will be instantiated and called as such:
- * SORTracker* obj = new SORTracker();
- * obj->add(name,score);
- * string param_2 = obj->get();
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement