直接模拟。。。
View Code
1 #include <iostream> 2 #include <cstring> 3 #include <queue> 4 using namespace std; 5 6 typedef pair<int,int> pii; 7 8 struct node 9 { 10 int id,kb; 11 node(){} 12 node(int a,int b) 13 { 14 id = b; 15 kb = a; 16 } 17 friend bool operator <(const node& a,const node& b) 18 { 19 if(a.kb == b.kb) 20 return a.id > b.id; 21 22 return a.kb < b.kb; 23 } 24 }; 25 26 int main() 27 { 28 int n; 29 while(cin >> n) 30 { 31 priority_queue<node> q[4]; 32 33 char str[5]; 34 int id = 1; 35 while(n --) 36 { 37 int a; 38 cin >> str >> a; 39 if(str[0] == 'I') 40 { 41 int b; 42 cin >> b; 43 q[a].push(node(b,id)); 44 id ++; 45 } 46 else 47 { 48 if(q[a].empty()) 49 { 50 cout << "EMPTY" << endl; 51 } 52 else 53 { 54 cout << q[a].top().id << endl; 55 q[a].pop(); 56 } 57 } 58 } 59 60 } 61 return 0; 62 }