算法分析
可以用 std::set
来维护被呼叫但没有来的人,再用一个变量 yet
来维护还没被呼叫的人
C++ 代码
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
int n, q;
cin >> n >> q;
set<int> called;
int yet = 1;
rep(qi, q) {
int type;
cin >> type;
if (type == 1) {
called.insert(yet++);
}
if (type == 2) {
int x;
cin >> x;
called.erase(x);
}
if (type == 3) {
int x = *called.begin();
cout << x << '\n';
}
}
return 0;
}