#include <bits/stdc++.h>
#define ll long long
#define int long long
#define re register
using namespace std;
const int N=1e5+5, INF=0x3f3f3f3f;
int n;
queue<string>Q;
map<string,int> zt;//0 不在;1 排队;2 游玩;
string last1,last2;
inline void START(int i){
if(i!=1){
if(last1!="")
Q.push(last1),zt[last1]=1;
if(last2!="")
Q.push(last2),zt[last2]=1;
if(!Q.size()){
printf("Error\n");return ;
}
string player1=Q.front();Q.pop();
if(!Q.size()){
last1=player1;last2="";
zt[player1]=2;
cout<<player1<<"\n";
}else{
string player2=Q.front();Q.pop();
last1=player1;last2=player2;
zt[player1]=2;zt[player2]=2;
cout<<player1<<' '<<player2<<"\n";
}
}else printf("Error\n");
}
inline void ARRIVE(string x){
if(zt[x]==1||zt[x]==2)printf("Error\n");
else{
Q.push(x);zt[x]=1;
printf("OK\n");
}
}
inline void LEAVE(string x){
if(zt[x]==1){
zt[x]=0;
queue<string>Q2;
while(Q.size()){
if(Q.front()!=x)Q2.push(Q.front());
Q.pop();
}
Q=Q2;
printf("OK\n");
}else printf("Error\n");
}
signed main(){//scanf & printf: "%lld"
/*freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);*/
ios::sync_with_stdio();
cin>>n;
for(re int i=1;i<=n;i++){
string s;cin>>s;
if(s=="start")START(i);
else if(s=="arrive"){
string k;cin>>k;
ARRIVE(k);
}else{
string k;cin>>k;
LEAVE(k);
}
}
return 0;
}
删除元素这一操作如何优化(或者求个正解