AcWing 132. 小组队列
原题链接
简单
作者:
wjie
,
2020-07-26 16:24:20
,
所有人可见
,
阅读 544
#include <iostream>
#include <cstdio>
#include <map>
#include <queue>
using namespace std;
const int N = 2e5 + 5;
int cas;
queue<int> whole, part[1005];
void input(int t, map<int, int> &maps)
{
int n, id;
for (int i = 1; i <= t; ++i)
{
scanf("%d", &n);
for (int j = 1; j <= n; ++j)
{
scanf("%d", &id);
maps[id] = i;
}
}
}
void enqueue(map<int, int> &maps)
{
int x;
scanf("%d", &x);
if (part[maps[x]].empty())
{
part[maps[x]].push(x);
whole.push(maps[x]);
}
else part[maps[x]].push(x);
}
int dequeue()
{
int res = part[whole.front()].front();
part[whole.front()].pop();
if (part[whole.front()].empty()) whole.pop();
return res;
}
void init(int x)
{
while (!whole.empty()) whole.pop();
for (int i = 1; i <= x; ++i)
{
while (!part[i].empty()) part[i].pop();
}
}
int main()
{
int t;
while (scanf("%d", &t) && t)
{
init(t);
printf("Scenario #%d\n", ++cas);
map<int, int> maps;
input(t, maps);
string op;
while (cin >> op && op.compare("STOP"))
{
// cout << op << endl;
if (!op.compare("ENQUEUE")) enqueue(maps);
else printf("%d\n", dequeue());
// cout << part[1].size() << " " << part[2].size() << endl;
}
printf("\n");
}
return 0;
}