#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
vector<int> vx;
inline int mp(int x) {return upper_bound(vx.begin(),vx.end(),x)-vx.begin();}
inline int log_2(int x) {return 31-__builtin_clz(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int lowbit(int x) {return x&-x;}
const int N = 1e6+10;
int f[N];
bool st[1010];
void solve()
{
int t;
int cnt = 0;
while(cin>>t,t)
{
cout<<"Scenario #"<<++cnt<<'\n';
queue<int> q[t+1];
//用q[0]表示总链
for(int i=1;i<=t;++i)
{
st[i] = 0;
int n;
cin>>n;
for(int j=1;j<=n;++j)
{
int x;
cin>>x;
f[x] = i;
}
}
//本题的核心在于可以多次入队出队
string s;
while(cin>>s,s!="STOP")
{
if(s == "ENQUEUE")
{
int x;
cin>>x;
if(!st[f[x]])
{
q[0].push(f[x]);
q[f[x]].push(x);
st[f[x]] = 1;
}
else
{
q[f[x]].push(x);
}
}
else if(s == "DEQUEUE")
{
//注意需要的p是根节点
int p = q[0].front();
cout<<q[p].front()<<'\n';
q[p].pop();
if(q[p].empty()) {q[0].pop();st[p] = 0;}
}
}
cout<<'\n';
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
//cin>>T;
while(T--)
{
solve();
}
}
标签:typedef,return,队列,long,Queue,int,vector,Team,vx
From: https://www.cnblogs.com/ruoye123456/p/18412001