题解
2023-07-26 09:39:05
发布于:河北
7阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define faster ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MAXN = 1e5 + 10; // team capacity of people
void solve(const int &t) {
map<int, int> team; // signed every single one own team id
for (int i = 0, k, a; i < t; i++) {
cin >> k;
for (int j = 0; j < k; j++) {
cin >> a;
team[a] = i;
}
}
int tid = 0;
map<int, int> itq; // signed every single team in team queue id
queue<int> q[MAXN];
int deq_id = 0, td, team_id, q_id;
string s;
while (cin >> s) {
if (s == "STOP") break;
else if (s == "ENQUEUE") {
cin >> td; // get team id, if in team queue, get the queue id, push it
team_id = team[td];
if (itq.count(team_id)) q_id = itq[team_id];
else itq[team_id] = q_id = tid++;
q[q_id].push(td);
} else {
// deque
int team_id = team[q[deq_id].front()];
cout << q[deq_id].front() << "\n";
q[deq_id].pop();
if (q[deq_id].empty()) { deq_id++; itq.erase(team_id); } // if this team is empty need id Plus 1 move to next
}
}
}
int main(){
faster;
int t;
cin >> t;
solve(t);
return 0;
}
这里空空如也
有帮助,赞一个