思路
优先队列
Code
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
priority_queue<int,vector<int>,greater<int> >q;
bool st[N];
int n,x;
string s;
int main(){
cin>>n;
for(int i=1;i<=N;i++) q.push(i);
while(n--){
cin>>s;
if(s[0]=='D'){
cin>>x;
if(st[x]) st[x]=false,puts("Successful"),q.push(x);
else puts("Failed");
}
else{
cout<<q.top()<<endl;
st[q.top()]=true;
q.pop();
}
}
return 0;
}
京公网安备 11010502036488号