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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#include <iostream> #include <algorithm> #include <queue> #include <vector> #include <cstdlib> #include <cstdio> #include <string> #include <cstring> #include <ctime> #include <iomanip> #include <cmath> #include <set> #include <map> #include <stack> using namespace std; int main(){ multiset<pair<int, int> > q; int cmd = 0; while (scanf(" %d",&cmd) != EOF){ if (!cmd) { break; }else if (cmd == 1) { //add client int k,p; scanf(" %d %d",&k,&p); q.insert(make_pair(p, k)); }else if (cmd == 2) { //high priority if(q.size()==0){ cout << 0 << endl; continue; } multiset<pair<int, int> >::iterator it = q.end(); it--; cout << (*it).second << endl; q.erase(it); }else if(cmd == 3){ //low proirity if(q.size()==0){ cout << 0 << endl; continue; } multiset<pair<int, int> >::iterator it = q.begin(); cout << (*it).second << endl; q.erase(it); } } return 0; } |
那帮老逼太机智了,双端优先队列他们居然用map实现也是diao。。。