#11 TLE 求助SOS!!!
  • 板块P9518 queue
  • 楼主lizeyuhello
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/3/17 21:49
  • 上次更新2024/3/18 12:12:02
查看原帖
#11 TLE 求助SOS!!!
730504
lizeyuhello楼主2024/3/17 21:49
#include<bits/stdc++.h>
using namespace std;

int n;
string p1, p2;
deque<string> q;
map<string, bool> f;

inline void solve()
{
	string op, s;
	cin >> op;
	if (op == "start")
	{
		if (p1 != "")
			q.push_back(p1);
		if (p2 != "")
			q.push_back(p2);
		if (q.empty())
			cout << "Error\n";
		else
		{
			p1 = p2 = "";
			if (!q.empty())
				p1 = q.front(), q.pop_front();
			if (!q.empty())
				p2 = q.front(), q.pop_front();
			cout << p1 << " " << p2 << '\n';
		}
	}
	else if (op == "arrive")
	{
		cin >> s;
		if (!f[s])
		{
			f[s] = 1, q.push_back(s);
			cout << "OK\n";
		}
		else
			cout << "Error\n";
	}
	else
	{
		cin >> s;
		if (p1 != s && p2 != s && f[s])
		{
			f[s] = 0, q.erase(find(q.begin(), q.end(), s));
			cout << "OK\n";
		}
		else
			cout << "Error\n";
	}
	return;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n;
	while (n--)
		solve();
 	return 0;
}
2024/3/17 21:49
加载中...