40分求助,hack数据全过!
  • 板块P9518 queue
  • 楼主Yan_Bo
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/8/13 22:43
  • 上次更新2023/11/3 03:59:55
查看原帖
40分求助,hack数据全过!
640368
Yan_Bo楼主2023/8/13 22:43
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,t=0;
string s="",ss="",a,o;
queue<string>q;
multiset<string>d;
map<string,int>mp;
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>o;
		if(o=="start"){
			if(t>=1)q.push(s);
			if(t>=2)q.push(ss);
			while(!q.empty()){
				if(d.find(q.front())==d.end())q.pop();
				else if(mp[q.front()]>=2)mp[q.front()]--,q.pop();
				else break;
			}
			if(q.empty()){
				cout<<"Error\n";
				t=0;
			}
			else {
				t=1;
				s=q.front();
				cout<<q.front()<<" ";
				q.pop();
				while(!q.empty()){
					if(d.find(q.front())==d.end())q.pop();
					else if(mp[q.front()]>=2)mp[q.front()]--,q.pop();
					else break;
				}
				if(!q.empty()){
					t++;
					ss=q.front();
					cout<<q.front();
					q.pop();
				}
				cout<<"\n";
			}
		}
		if(o=="arrive"){
			cin>>a;
			if(d.find(a)!=d.end()){
				cout<<"Error\n";
				continue;
			}
			d.insert(a);
			q.push(a);
			cout<<"OK\n";
			mp[a]++;
		}
		if(o=="leave"){
			cin>>a;
			if((t>=1&&s==a)||(ss==a&&t==2)||d.find(a)==d.end()){
				cout<<"Error\n";
				continue;
			}
			cout<<"OK\n";
			d.erase(d.find(a));
		}
	}
}
2023/8/13 22:43
加载中...