set特性
新建 Microsoft Office Word 文档
https://ac.nowcoder.com/acm/problem/17889
思路
利用set红黑树的特性,begin 最小,同时用一个数组去判断是否存在。
// Oj.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 #include<bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 100005; const ll Mod = 1000000009; int r[N] = { 1 }; int main() { ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); set<int>st; for (int i = 1; i < N; i++) { st.insert(i); } int n; cin >> n; while (n--) { string s; cin >> s; if (s == "New") { int j = *st.begin(); cout <<j<< endl; st.erase(j); r[j] = -1; } else { int numb; cin >> numb; if (r[numb] == -1) { cout << "Successful\n"; st.insert(numb); r[numb] = 0; } else { cout << "Failed\n"; } } } }